This is a discussion on How can I tell if a time was yesterday? within the PHP Language forums, part of the PHP Programming Forums category; On Wed, 15 Aug 2007 20:45:33 +0200, Toby A Inkster <usenet200707@tobyinkster.co.uk> wrote: > ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
On Wed, 15 Aug 2007 20:45:33 +0200, Toby A Inkster
<usenet200707@tobyinkster.co.uk> wrote: > Rik wrote: > >> function is_today($timestamp){ >> return date('d',$timestamp) == date('d'); >> } > > The following will return TRUE: > > is_today(strtotime('15 Feb 1986')); > > Better would be: > > function is_today ($ts) > { return date('Ymd',$ts)==date('Ymd'); } Up it does. Kept it as simple as possible as the op stated it could only be today or yesterday: hence not a month difference etc. Then again this will be up for it when the difference _can_ run longer indeed. -- Rik Wasmus |
|
|||
|
Álvaro G. Vicario escribió:
> FFMG escribió: >> Given a time I want to know if it is today or yesterday, (on the >> server). > > function is_yesterday($timestamp){ // NOT TESTED > $start = mktime(0, 0, 0, > date('n', time()), date('j', time()), date('Y', time())); > $end = mktime(0, 0, 0, > date('n', time()), date('j', time()), date('Y', time())); > > return ($timestamp>=$start) && ($timestamp<$end) > } I'm sorry, I didn't understand the specs and my code contains a huge type that makes it useless; $end should be; $end = mktime(0, 0, 0, date('n', time()), date('j', time())+1, date('Y', time())); Anyway, I hope it can at least give some ideas... -- -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain ++ Mi sitio sobre programación web: http://bits.demogracia.com +- Mi web de humor austrohúngaro: http://www.demogracia.com -- |