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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 motoradmin系统的多对多配置
    • ¥15 求组态王串口自定义通信配置方法或代码?
    • ¥15 实验 :UML2.0 结构建模
    • ¥20 用vivado写数字逻辑实验报告撰写,FPGA实验
    • ¥15 为什么shp文件会有这种小方块?
    • ¥15 ecplise在连接数据库时显示加载驱动成功但是数据库连接失败
    • ¥15 visionmaster启动失败,提示为“机器不满足授权而被禁用”
    • ¥15 IDEA中圈复杂度如何具体设置
    • ¥50 labview采集不了数据
    • ¥15 Multisim红外倒车雷达仿真中距离问题