Pagina 1 din 1

strtotime cu sir "first day of last week" e incorect

Scris: Joi Noi 05, 2020
de Marius
Folosind acest cod in php:

Cod: SelectaĊ£i tot

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

echo $from_date;  // 2020-10-01 00:00:00
returneaza: "2020-10-01 00:00:00", dar rezultatul corect este "2020-10-25 00:00:00".
De ce returneaza prima zi din luna?

Cum pot obtine in php prima zi din ultima saptamana (si ultima zi din ultima saptamana)?

strtotime cu sir "first day of last week" e incorect

Scris: Joi Noi 05, 2020
de MarPlo
Ca sa obtii in php "prima zi din ultima saptamana", incearca strtotime() cu sirul: "last week last sunday".
Iar pentru "ultima zi din ultima saptamana", foloseste fraza: "last day of last week".

Cod: SelectaĊ£i tot

$first_day = date('Y-m-d 00:00:00', strtotime('last week last sunday'));
$last_day = date('Y-m-d 00:00:00', strtotime('last day of last week'));

echo $first_day;  // 2020-10-25 00:00:00
echo $last_day;  // 2020-11-30 00:00:00