How to Get Yesterday and Tomorrow Date in PHP

AuthorHariom Prajapati

Pubish Date25 Jun 2022

categoryPHP

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

php

 

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

php

 

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"));
?>

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

 

Output

php

 

Comments 0

Leave a comment