Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get previous day in PHP

Tags:

php

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.

like image 272
Istiak Mahmood Avatar asked Aug 10 '15 14:08

Istiak Mahmood


People also ask

How to get the date of previous day in PHP?

Using strtotime() to Get Yesterday's Date in PHP strtotime() is a built-in PHP function parses an English textual DateTime into a Unix timestamp from January 1, 1970, 00:00:00 GMT.

How can I get tomorrow day in PHP?

$newDate = date('Y-m-d', strtotime('tomorrow')); echo $newDate; ?>


1 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');
like image 119
Hirdesh Vishwdewa Avatar answered Oct 21 '22 06:10

Hirdesh Vishwdewa