开发者

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 "y开发者_运维知识库esterday" 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' }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜