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 metadata提取的PDF元数据,如何转换为一个Excel
    • ¥15 关于arduino编程toCharArray()函数的使用
    • ¥100 vc++混合CEF采用CLR方式编译报错
    • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
    • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
    • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
    • ¥50 如何openEuler 22.03上安装配置drbd
    • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
    • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
    • ¥15 Windows11, backspace, enter, space键失灵