1$dayofweek = date('w', strtotime($date));
2$result = date('Y-m-d', strtotime(($day - $dayofweek).' day', strtotime($date)));
1$lastDateOfNextMonth =strtotime('last day of next month') ;
2
3$lastDay = date('d/m/Y', $lastDateOfNextMonth);
4
5
6
7print_r($lastDay);
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$mydate = '2016-01-01';
2echo date('l, F jS, Y', strtotime($mydate));
3# Friday, January 1st, 2016
4