tags:

views:

54

answers:

3

Hi.

Is it possible to check if the date ("j-1 F-1")???

I'm a noob so some script would help! Postdate is in a format like: 14 October.

if ($postdate == date("j F")) {$postdate = "today";} THIS WORKS...

But I need to check the $postdate for the "yesterday" value as well!

Q: How to check for yesterday? that is, date()-1 somehow.

Thanks again

+1  A: 
date('j F', strtotime('-1 day'));

Will retrieve the "yesterday" timestamp. So :

if ($postdate == date('j F', strtotime('-1 day'))) {$postdate = "yesterday";}
Damien MATHIEU
A: 

use strtotime or mktime and then check if your date is between that value and todays timestamp.

if($date > strtotime('yesterday') && $date < time()) { echo 'yesterday or today' }

if($date > mktime(0,0,0,date('n'),date('j')-1) && $date < time()) { echo 'yesterday or today' }
knittl
+1  A: 
$yesterday = date('j F', mktime(0,0,0, date('m'), date('d')-1, date('Y')));

The "magic" is in the mktime call. I seriously advise you to read the relevant parts of the PHP manual: this is almost a verbatim duplication of Example #3!

The Wicked Flea
Well with strtotime, it's much more readable.
Damien MATHIEU
+1 for "read the relevant parts of the PHP manual", +1 for dmathieu's comment (I'd add "and more reliable").
GZipp