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 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘