简体   繁体   中英

PHP - strtotime using phrase "first day of last week" not correct

Using the code:

$from_date = date("Y-m-d 00:00:00", strtotime("first day of last week"));

returns: "2020-10-01 00:00:00", when I expect it to return "2020-10-25 00:00:00".

Why is it returning the first day of the month?

How can I get the first day of last week (and also the last day of last week)?

try this:

<?php

$from_date = date("Y-m-d 00:00:00", strtotime("last week last sunday"));

echo $from_date;
//returns 2020-10-25 00:00:00;

I've tested the dates on 7.1.0 version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM