TheRob
TheRob

Reputation: 133

get number of days in the first week of the month in php

i woder how can i get the number of days in the first week of the month in php, for example..

march have 4 days in the first week.

How can I achieve that ??

Upvotes: 0

Views: 116

Answers (1)

Qirel
Qirel

Reputation: 26460

March this year has 5 days in its first week, not 4; Wednesday 1st through Sunday 5th makes the first week on this side of the month.

So you can simply use the date of the first Sunday of each month to achieve your result

$first_sunday = new DateTime('first sunday of this month');
echo $first_sunday->format("j"); // Output: 5 for March 2017

Upvotes: 3

Related Questions