Blog Posts » MySQL » MySQL Date & Time Functions
MySQL Date & Time Functions
Dibawah ini adalah beberapa fungsi Date & Time MySQL sebagai bahan materi pengembangan di anggit.com. Tidak menutup kemungkinan untuk Anda pelajari juga.
1. DATE_FORMAT(date, format)
[Textarea][RAW][Download]
- mysql> SELECT DATE_FORMAT('2009-10-04 22:23:00', '%Y%m%d%H%i%s');
- -> 20091004222300
- mysql> SELECT DATE_FORMAT('2009-10-04', '%Y%m%d%H%i%s');
- -> 20091004000000
- mysql> SELECT DATE_FORMAT('2009-10-04', GET_FORMAT(DATETIME,'INTERNAL'));
- -> 20091004000000
2. GET_FORMAT()
[Textarea][RAW][Download]
- GET_FORMAT(DATE,'USA') -> '%m.%d.%Y'
- GET_FORMAT(DATE,'JIS') -> '%Y-%m-%d'
- GET_FORMAT(DATE,'ISO') -> '%Y-%m-%d'
- GET_FORMAT(DATE,'EUR') -> '%d.%m.%Y'
- GET_FORMAT(DATE,'INTERNAL') -> '%Y%m%d'
- GET_FORMAT(DATETIME,'USA') -> '%Y-%m-%d %H.%i.%s'
- GET_FORMAT(DATETIME,'JIS') -> '%Y-%m-%d %H:%i:%s'
- GET_FORMAT(DATETIME,'ISO') -> '%Y-%m-%d %H:%i:%s'
- GET_FORMAT(DATETIME,'EUR') -> '%Y-%m-%d %H.%i.%s'
- GET_FORMAT(DATETIME,'INTERNAL') -> '%Y%m%d%H%i%s'
- GET_FORMAT(TIME,'USA') -> '%h:%i:%s %p'
- GET_FORMAT(TIME,'JIS') -> '%H:%i:%s'
- GET_FORMAT(TIME,'ISO') -> '%H:%i:%s'
- GET_FORMAT(TIME,'EUR') -> '%H.%i.%s'
- GET_FORMAT(TIME,'INTERNAL') -> '%H%i%s'
3. STR_TO_DATE(str, format)
[Textarea][RAW][Download]
- mysql> SELECT STR_TO_DATE('20130501000000', '%Y%m%d%H%i%s');
- -> '2013-05-01 00:00:00'
4. UNIX_TIMESTAMP(date)
[Textarea][RAW][Download]
- mysql> SELECT UNIX_TIMESTAMP();
- -> 1196440210
- mysql> SELECT UNIX_TIMESTAMP('2007-11-30 10:30:19');
- -> 1196440219
- mysql> SELECT UNIX_TIMESTAMP('20071130103019');
- -> 1196440219
- mysql> SELECT UNIX_TIMESTAMP('1980-01-01');
- -> 315507600
5. FROM_UNIXTIME(unix_timestamp, format)
[Textarea][RAW][Download]
- mysql> SELECT FROM_UNIXTIME(1234567890, '%Y%m%d%H%i%s');
- -> 20090214063130
More: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html