How can I tell if a time was yesterday?

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: > ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 08-15-2007
Rik
 
Posts: n/a
Default Re: How can I tell if a time was yesterday?

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
Reply With Quote
  #12 (permalink)  
Old 08-15-2007
Álvaro G. Vicario
 
Posts: n/a
Default Re: How can I tell if a time was yesterday?

Á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
--
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:26 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0