FW: Date() finding yesterday

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The easiest way I found to do this is using mktime().
If you don't care about the time for the date you can use this...

$yesterday = mktime(0,0,0,date("m"),date("d")-1,date("Y"));

This translates to yesterday morning after midnight.

If you want the present time, only 24 hours before, use this...

$yesterday =
mktime(date("H"),date("i"),date("s"),date("m"),date("d")-1,date("Y"));

To display the date use...

date( "m/d/Y", $yesterday );

Or you can put the mktime code in play of $yesterday in the above line
of
code.

Good luck,



Jef

-----Original Message-----
From: Scott Hurring [mailto:scott.hurring.lists@xxxxxxxxx] 
Sent: Sunday, May 21, 2006 12:18 PM
To: Rabin Vincent; php-general@xxxxxxxxxxxxx
Subject: Re:  Date() finding yesterday

mktime also works: http://php.net/mktime:

date("Y-m-d", mktime( ... ))

On 5/21/06, Rabin Vincent <rabin@xxxxxx> wrote:
>
> On 5/21/06, John Taylor-Johnston
> <John.Taylor-Johnston@xxxxxxxxxxxxxxxxxxxxx> wrote:
> > I cannot seem to get this right. How can I produce yesterday?
> >
> > $today = date("Y-m-d");
> > $yesterday = date("Y-m-") . date("d")-1;
> > $yesterday = date("Y-m-d")-1;
> > $yesterday = date("Y-m-"."d"-1);
> >
> > I've been looking at the manual :) ...
>
> Use php.net/strtotime:
>
> $yesterday = date('Y-m-d', strtotime('-1 day'));
>
> Rabin
>
> --
> http://rab.in
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Scott Hurring [scott dot hurring dot lists at gmail dot com]
http://hurring.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux