dsfb20227 2019-04-21 15:14 采纳率: 0%
浏览 91

strtotime在星期天返回同一天

So I have 5 variables that I use to store last weeks dates using the php function strtotime()

The only problem is, every Sunday the dates return the same dates. Like today for instance, using $monday = date('Y-m-d', strtotime('monday last week')); will return me a date of 2019-04-08

Obviously being the 2019-04-21 today that should be 2019-04-08. The problem starts here though, if I use this $tuesday = date('Y-m-d', strtotime('tuesday last week')); it will return me a date of 2019-04-08 and the date today is 2019-04-21 so it should return return me the date 2019-04-09.

The same is true if I try any of the weekdays. They all return me the same date, 2019-04-08.

What's more is its also true if you are using date('Y-m-d', strtotime('monday this week'));

works for monday but returns monday for all of the days of the week when on a Sunday.

I saw someone say use a function, so I was researching on here and tried it but it returned the same result.

//// function I tried but it proved to produce the same results.///////
function lastfriday() {
        return date('Y-m-d', date('N')==5 ? strtotime('today') : strtotime('last friday'));
    }






////////// this is the code I have been using but as I explained, every Sunday it gets buggy
echo $monday = date( 'Y-m-d', strtotime( 'monday last week' ) );
echo $tuesday = date( 'Y-m-d', strtotime( 'tuesday last week' ) );
echo $wednesday = date( 'Y-m-d', strtotime( 'wednesday last week' ) );
echo $thursday = date( 'Y-m-d', strtotime( 'thursday last week' ) );
echo $friday = date( 'Y-m-d', strtotime( 'friday last week' ) );
echo $saturday = date( 'Y-m-d', strtotime( 'saturday last week' ) );

running that code on today 2019-04-21 produces the results

2019-04-08
2019-04-08
2019-04-08
2019-04-08
2019-04-08
2019-04-08
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 PADS Logic 原理图
    • ¥15 PADS Logic 图标
    • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
    • ¥20 气象站点数据求取中~
    • ¥15 如何获取APP内弹出的网址链接
    • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了