简体   繁体   中英

How to check if date() function minus one?

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

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

Will retrieve the "yesterday" timestamp. So :

if ($postdate == date('j F', strtotime('-1 day'))) {$postdate = "yesterday";}
$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 !

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' }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM