php strtotime “last monday” if today is monday?

后端 未结 8 1763
攒了一身酷
攒了一身酷 2020-11-30 03:45

I want to use strtotime(\"last Monday\").

The thing is, if today IS MONDAY, what does it return? It seems to be returning the date for the monday of la

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 04:12

    If today is Monday, strtotime("last Monday") will return a date 7 days in the past. Why don't you just check if today is Monday and if yes, return today's date and if not, return last week?

    That would be a foolproof way of doing this.

    if (date('N', time()) == 1) return date('Y-m-d');
    else return date('Y-m-d', strtotime('last Monday'));
    

    http://us2.php.net/manual/en/function.date.php

提交回复
热议问题