D
D
Denis2021-08-10 14:48:02
PHP
Denis, 2021-08-10 14:48:02

Why does the date function in php work like this?

Does the date function work differently?
I need a Monday from a specific date. And each time produces different values.
I run
date('YmW', strtotime("2021-04-04 16:15:10" . " monday this week");
I get what I need
20210313 I
run the same thing in the project
date('YmW', strtotime("2021-04-04 16:15:10" . " monday this week"));
but it gives out 20210414
this happens because 2021-04-04
is Sunday, in the replay from this Sunday if you request monday this week it will be 03/29/2021, i.e. the previous Monday, and in the project we will get 04/5/2021 the Monday following immediately after Sunday...
how would now and where to change the settings so that in the project so that it counts as in the replay? Tell me who knows?
'YmW' was already before me))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitsliputsli, 2021-08-10
@Vitsliputsli

On the second server, the week starts on Sunday instead of Monday. Probably there is a very old version of php, in modern versions the week always starts on Monday. Either update or see how to override the first day of the week.

A
Andrey Alexandrov, 2021-08-11
@ImidgX

Try to strtotime
put the time zone before the call: Perhaps this is the case.
date_default_timezone_set('Europe/Moscow');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question