How to Get Yesterday and Tomorrow Date in PHP

 

In this tutorial we will learn how to get yesterday and tomorrow date in PHP with example.


We also learn that how to get date of days before yesterday in php and how to get dates after tomorrow in php.

 

1) How to get yesterday date in PHP

Just follow the below code to get yesterday date in php.

<?php 

echo "Yesterday was " . date('Y-m-d',strtotime("yesterday"));

?>


Output

image


You can get yesterday date in php and also get all dates before yesterday in php by using below code.

<?php 

echo "Yesterday was - " . date('Y-m-d',strtotime("-1 days"))

echo '<br>';

echo "Day before yesterday was - " . date('Y-m-d',strtotime("-2 days"));

?>


Output

image

 

Note : Similarly we can get previous days date by changing in -1 days.

 

2) How to get tomorrow date in PHP

Just follow the below code to get tomorrow date in php.

<?php 

echo " Tomorrow date will be " . date('Y-m-d',strtotime("tomorrow"));

?>


You can get tomorrow date in php and also get all dates after tomorrow in php by using below code.

<?php 

echo "Tomorrow date will be - " . date('Y-m-d',strtotime("+1 days"))

echo '<br>';

echo "Date after tomorrow will be - " . date('Y-m-d',strtotime("+2 days"));

?>


Output

image

 

Note : Similarly we can get next days date by changing in +1 days.

 

Related Topics