How to get Date after or before some days on current date or another date using php

In this post im share with you guys How to get Date after or before some days on current date or another date using php

our current date is - 2023-02-23

I want to get date before current date -2 days : 

using bellow method we are found new date is - 2023-02-21



<?php
$date = date_create(date("Y-m-d"));
date_add($date, date_interval_create_from_date_string('-2 days'));
echo date_format($date, 'Y-m-d');


when i want to get date after current date +2 days : 

we are pass value in +2 days 

our current date is - 2023-02-23

using bellow method we are found new date is - 2023-02-25



<?php
$date = date_create(date("Y-m-d"));
date_add($date, date_interval_create_from_date_string('+2 days'));
echo date_format($date, 'Y-m-d');