1$timestamp = strtotime('2009-10-22');
2
3$day = date('D', $timestamp);
4var_dump($day);
1// get day of month php
2// Method 1; some server not work, I had check php 7.3.24 not worked, php 7.3.8 worked
3cal_days_in_month(CAL_GREGORIAN, $month, $year)
4echo (cal_days_in_month(CAL_GREGORIAN, 2, 2020)); // => 29
5
6// Method 2;
7function days_in_month($month, $year) {
8 // calculate number of days in a month
9 return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
10}
11
12// Method 3;
13echo (date('t', strtotime('2020-02-1'))); // 29
14
15
16
1// how to check the day of any date in php?
2
3//Our YYYY-MM-DD date string.
4$date = $request->start_date;
5
6//Convert the date string into a unix timestamp.
7$unixTimestamp = strtotime($date);
8
9//Get the day of the week using PHP's date function.
10$dayOfWeek = date("l", $unixTimestamp);
11
12//Print out the day that our date fell on.
13$day = $date . ' fell on a ' . $dayOfWeek;
1You can use the date function. I'm using strtotime to get the timestamp to that day ; there are other solutions, like mktime, for instance.
2
3For instance, with the 'D' modifier, for the textual representation in three letters :
4
5$timestamp = strtotime('2009-10-22');
6
7$day = date('D', $timestamp);
8var_dump($day);
9You will get :
10
11string 'Thu' (length=3)
12And with the 'l' modifier, for the full textual representation :
13
14$day = date('l', $timestamp);
15var_dump($day);
16You get :
17
18string 'Thursday' (length=8)
19Or the 'w' modifier, to get to number of the day (0 to 6, 0 being sunday, and 6 being saturday) :
20
21$day = date('w', $timestamp);
22var_dump($day);
23You'll obtain :
24
25string '4' (length=1)
26