Rabu, 18 Januari 2012

DATE_FORMAT(date,format)

Tabel referensi penggunaan format sebagai berikut:


Format
Description
%a
Abbreviated weekday name (Sun...Sat)
%b
Abbreviated month name (Jan ... Dec)
%c
Month, numeric (1....12)
%D
Day of month with English suffix (1st, 2nd, 3rd, ....)
%d
Day of month, numeric (00-31)
%e
Day of month, numeric (0-31)
%f
Microseconds (000000.....999999)
%H
Hour (00-23)
%h
Hour (01-12)
%I
Hour (01-12)
%i
Minutes, numeric (00-59)
%j
Day of year (001-366)
%k
Hour (0-23)
%l
Hour (1-12)
%M
Month name (January .... December)
%m
Month, numeric (00-12)
%p
AM or PM
%r
Time, 12-hour (hh:mm:ss AM or PM)
%S
Seconds (00-59)
%s
Seconds (00-59)
%T
Time, 24-hour (hh:mm:ss)
%U
Week (00-53) where Sunday is the first day of week
%u
Week (00-53) where Monday is the first day of week
%V
Week (01-53) where Sunday is the first day of week, used with %X
%v
Week (01-53) where Monday is the first day of week, used with %x
%W
Weekday name (Sunday.....Saturday)
%w
Day of the week (0=Sunday, 6=Saturday)
%X
Year of the week where Sunday is the first day of week, four digits, used with %V
%x
Year of the week where Monday is the first day of week, four digits, used with %v
%Y
Year, four digits
%y
Year, two digits

sumber:http://www.w3schools.com/sql/func_date_format.asp
Contoh Penggunaan:
Untuk merubah format dengan date_format
SELECT date_format(namafield,'%d-%m-%Y') as newdate from namatabel;
hasil:
sebelum : 2011-11-10 menjadi 10-11-2011

 Untuk query select berdasarkan pada bulan atau tahun

SELECT *  FROM namatabel where date_format(tanggal,'%M') ='January' and date_format(tanggal,'%y') ='2014'
hasil:
Seluruh data yang ada di bulan Januari 2014. Tanpa harus mengetahui tanggal awal dan akhir bulan.


Categories: , , , ,

2 komentar:

  1. keren sekali

    Free Download software full, crack, Serial Number, Patch, Premium Account, Movie, Music, Ebook, Game Update Daily....

    http://cyber-show.blogspot.com/

    BalasHapus

Subscribe to RSS Feed Follow me on Twitter!