Jika pada tutorial sebelumnya kita mempelajari Tipe Data Numerik MySQL dan Tipe Data Huruf (String) MySQL, tipe data selanjutnya yang tersedia dalam MySQL adalah tipe data date (tanggal), tipe data ini digunakan untuk menyimpan data yang berkaitan dengan tanggal dan waktu. Tipe data date, terdiri dari: DATE, TIME, DATETIME, TIMESTAMP, dan YEAR.
Using a datetime field from a mysql database e.g. '2012-03-24 17:45:12'. There is a bit confusing logic may appear using year week number: format ( 'YW' ). PHPEOL;?will output 201801, not 201901 nor 201852, because of strange ISO8601-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.
![Date Date](/uploads/1/2/5/5/125509476/825163629.png)
So be careful when using this output with something important (i know projects where this was used to form MySQL partitions). I believe this is a bug but its note-worthy if it is intended (I am using PHP 5.5.3).$ php -versionPHP Warning: Module 'xdebug' already loaded in Unknown on line 0PHP 5.5.3-1ubuntu2.1 (cli) (built: Dec 12 2013 04:24:35)Copyright (c) 1997-2013 The PHP GroupZend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologieswith Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethanswith Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend TechnologiesWhat is happening: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.format('Y-m-d h:i:s')'.
PHPEOL;vardump ( $nowUtc - format ( 'Y-m-d h:i:s' ));$nowUtc - setTimezone ( new DateTimeZone ( 'Australia/Sydney' ) );echo '$nowUtc-setTimezone( new DateTimeZone( 'Australia/Sydney' ) )'. PHPEOL;vardump ( $nowUtc );echo '$nowUtc-format('Y-m-d h:i:s')'.