Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get date of yesterday using php?

Tags:

date

php

I want to get the yesterday date using specific date format in php this is the format:

$today = date("d.m.Y"); //15.04.2013 

Is it possible?

Take consideration of month and years if they should be changed in respective.

like image 805
unique_programmer Avatar asked Apr 15 '13 06:04

unique_programmer


People also ask

How can I get current date and previous date in PHP?

You can simply use the PHP date() function to get the current data and time in various format, for example, date('d-m-y h:i:s') , date('d/m/y H:i:s') , and so on.

How can I get tomorrow date in PHP?

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

What is Strtotime PHP?

The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.


2 Answers

there you go

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

this will work also if month change

like image 183
Fabio Avatar answered Sep 19 '22 08:09

Fabio


try this

        $tz    = new DateTimeZone('Your Time Zone');         $date  = new DateTime($today,$tz);         $interval = new DateInterval('P1D');         $date->sub($interval);           echo $date->format('d.m.y');          ?>            
like image 20
alwaysLearn Avatar answered Sep 21 '22 08:09

alwaysLearn