1$timestamp = strtotime('2009-10-22');
2
3$day = date('D', $timestamp);
4var_dump($day);
1$dayofweek = date('w', strtotime($date));
2$result = date('Y-m-d', strtotime(($day - $dayofweek).' day', strtotime($date)));
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<?php
2// set the default timezone to use. Available since PHP 5.1
3date_default_timezone_set('UTC');
4
5
6// Prints something like: Monday
7echo date("l");
8
9// Prints something like: Monday 8th of August 2005 03:12:46 PM
10echo date('l jS \of F Y h:i:s A');
11
12// Prints: July 1, 2000 is on a Saturday
13echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));
14
15/* use the constants in the format parameter */
16// prints something like: Wed, 25 Sep 2013 15:28:57 -0700
17echo date(DATE_RFC2822);
18
19// prints something like: 2000-07-01T00:00:00+00:00
20echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));
21?>