How to determine the n-th day of the week of a specific date in php

I am working on a calendar script where I need to repeat the calendar event, for example, "Repeat every 1st Tuesday of every month"

In the above example. How do you get "1st"?

for example, today - June 12, 2009, this would mean "2nd Friday of June." How do I get the 2nd?

Thank you in advance

+3
source share
2 answers

Divide by 7 and round:

ceil(date('j') / 7);
+16
source

It works:

<?php

$date = date('Y-m-d', mktime(0, 0, 0, date('m'), 1, date('y')));

echo date('Y-m-d', strtotime($date.'next tuesday'));

?>

The first line creates a date that is on the first day of this month. The second line will receive next Tuesday from $ date.

date mktime strtotime.

+3

Source: https://habr.com/ru/post/1710327/


All Articles