H
H
hollanditkzn2018-03-26 14:43:27
PHP
hollanditkzn, 2018-03-26 14:43:27

How to display the days of Monday and Sunday of a certain amount of the week?

How to make it so that, for example, you indicate the 13th week, which is now going on, it outputs 26.03 - 1.06
. You indicate the 11th week, then it indicated 12.03 - 18.03, Well, accordingly, if the 6th week, then 5 - 11.02.
But with this approach

<?= date('d.m', strtotime('13 week last Monday')).' - '.date('d.m' , strtotime('13 week Sunday')) ?>

25.06 - 01.07 is indicated, not 26.03 - 01.06.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Hog, 2018-03-26
@hollanditkzn

The parser is very ambiguous ...
But in your case, you can put it like this

$date_start = new DateTimeImmutable('13 week first monday of Jan this year - 1 week');
$date_end = $date_start->modify('+6 days');

echo $date_start->format('d.m') .' - '. $date_end->format('d.m');
// 26.03 - 01.04

Instead of "13" - you can substitute any week. Instead of "this year" - any year

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question