Code | Output |
$d = new DateTime('now');
echo $d->format('Y-m-d') ; | 2021-01-24 |
$d = new DateTime('19 July 2018');
echo $d->format('Y-m-d') ; | 2018-07-19 |
$d = new DateTime('Tomorrow');
echo $d->format('Y-m-d') ; | 2021-01-25 |
$d = new DateTime('Yesterday');
echo $d->format('Y-m-d') ; | 2021-01-23 |
$d = new DateTime('+1 day');
echo $d->format('Y-m-d') ; | 2021-01-25 |
$d = new DateTime('+1 week');
echo $d->format('Y-m-d') ; | 2021-01-31 |
$d = new DateTime('+1 week 5 days');
echo $d->format('Y-m-d') ; | 2021-02-05 |
$d = new DateTime('+1 month');
echo $d->format('Y-m-d') ; | 2021-02-24 |
$d = new DateTime('+1 month 10 days');
echo $d->format('Y-m-d') ; | 2021-03-06 |
$d = new DateTime('+3 months -1 day');
echo $d->format('Y-m-d') ; | 2021-04-23 |
$d = new DateTime('+3 years');
echo $d->format('Y-m-d') ; | 2024-01-24 |
$d = new DateTime('+1 year 5 days');
echo $d->format('Y-m-d') ; | 2022-01-29 |
$d = new DateTime('Monday');
echo $d->format('Y-m-d') ; | 2021-01-25 |
$d = new DateTime('Monday +1 day ');
echo $d->format('Y-m-d') ; | 2021-01-26 |
$d = new DateTime('first day of this month');
echo $d->format('Y-m-d') ; | 2021-01-01 |
$d = new DateTime('last day of this month');
echo $d->format('Y-m-d') ; | 2021-01-31 |
$d = new DateTime('first day of previous month');
echo $d->format('Y-m-d') ; | 2020-12-01 |
$d = new DateTime('last day of previous month');
echo $d->format('Y-m-d') ; | 2020-12-31 |
$d = new DateTime('first day of next month');
echo $d->format('Y-m-d') ; | 2021-02-01 |
$d = new DateTime('last day of next month');
echo $d->format('Y-m-d') ; | 2021-02-28 |
$d = new DateTime('last day of next month +1 hour');
echo $d->format('Y-m-d : H:i:s') ; | 2021-02-28 : 23:57:59 |
$d = new DateTime('Monday +1 hour +20 minutes +10 seconds');
echo $d->format('Y-m-d : H:i:s') ; | 2021-01-25 : 01:20:10 |
$d = DateTime::createFromFormat('d-m-Y', '11-06-2018');
$d = $d->modify('next monday');
echo $d->format('Y-m-d') ; | 2018-06-18 |
echo date('m-d-Y',strtotime('24-06-2018 next Monday '));
| 06-25-2018 |
06-25-2018Here we are getting output as date object and then converting to string by using