I know how to get the current date in PHP like so---

echo date("Y/m/d") 

But I am not sure how to get it the previous day. I mean today is 2015-08-10, so how I can get yesterday's date 2015-08-09.

UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY) 

Is it the solution, but do not know how it can solve my problem.

Does anyone know how to get the previous day in the PHP?

I have looked a lot but did not find any simple solution for this, anyone knows any solution for this problem. Thanks in advance.

2

4 Answers

Use this-

date('Y/m/d',strtotime("-1 days")); 

Or Use DateTime class like this-

$date = new DateTime(); echo $date->modify("-1 days")->format('Y-m-d'); 

Try this

date('Y-m-d', strtotime('-1 day', strtotime('2015-08-10'))) 

And you will get the previous day of 2015-08-10, To get the previous date from current date simple use this.

date('Y-m-d', strtotime("-1 days")); 

For more details follow the official site

You can modify a PHP DateTime object, it's fairly simple to add or subtract date intervals, this is the first example in the manual.

<?php $date = new DateTime('2006-12-12'); $date->modify('+1 day'); echo $date->format('Y-m-d'); ?> 

date modify

Get yesterday :

$hour = 12; $today = strtotime("$hour:00:00"); $yesterday = strtotime("-1 day", $today); 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy