will output 201801, not 201901 nor 201852, because of strange ISO_8601-2004 standard: the first calendar week of a year is that one which includes the first Thursday of that year, so this date (it is Monday) do belong to the first week of 2019 (this is why 'W' format gives 01), but internal timestamp is of 2018 (and 'Y' format obey this), therefore getting us unexpected result of 201801. So be careful when using this output with something important (i know projects where this was used to form MySQL partitions).

function last_day_of_feb ($year) {# The 0th day of a month is the same as the last day of the month before$ultimo_feb_str = $year . "-03-00"; $ultimo_feb_date = date_create($ultimo_feb_str);$return = date_format($ultimo_feb_date, "Y-m-d"); return $return;}

The udate function is a great start, but the formatting of the milliseconds is a little off. If it is within the first 100000 microseconds then the string will be less than 6 characters, so 0.012435 will appear as 0.12345. The revision below fixes this.

function udate($strFormat = 'u', $uTimeStamp = null){

// If the time wasn't provided then fill it in if (is_null($uTimeStamp)) { $uTimeStamp = microtime(true); }

// Round the time down to the second $dtTimeStamp = floor($uTimeStamp);

// Replace the milliseconds in the date format string // Then use the date function to process the rest of the string return date(preg_replace('`(?<!\\\\)u`', $strMilliseconds, $strFormat), $dtTimeStamp);}

DateTime()->format() will modify the timezone. So do not expect the public date property to be returned (format mask applied) based on the current public timezone property. format will decide that when calling ->format() it will use the server timezone which eliminates all usefulness of ->setTimezone().