Directly in command mode
Date Format Function Date_format ()
code is as follows |
copy code |
mysql> Select Date_format (now (), '%Y '); +-------------------------+ | date_format (Now (), '%Y ') | +-------------------------+ | 2009 | +-------------------------+ 1 row in Set (0.00 sec) Extension:%Y: Year%c: Month%d: Day%H: Hours%i: Minutes%s: sec Mysql> Select Date_format (now (), '%y-%c-%d%h:%i:%s '); +----------------------------------------+ | date_format (Now (), '%y-%c-%d%h:%i:%s ') | +----------------------------------------+ | 2009-8-07 06:59:40 | +----------------------------------------+ 1 row in Set (0.00 sec)--- |
About the Date_format function
Date_format (Date,format)
Formats the date value based on the format string. The following modifiers can be used in the format string:%m month name (January ...). December)
%w Week name (Sunday ...) Saturday)
%d The date of the month with English prefix (1st, 2nd, 3rd, and so on). )
%Y years, numbers, 4-bit
%y years, numbers, 2-bit
%a name of the week (Sun ...) Sat)
Days in%d months, numbers (00 ...). 31)
%e the number of days in the month, numbers (0 ...). 31)
%m Month, number (01 ...) 12)
%c month, number (1 ...). 12)
%b abbreviated month name (...) DEC)
%j the number of days in a year (001 ...). 366)
%H hours (00 .....) 23)
%k hours (0 .....) 23)
%h hours (01 .....) 12)
%I Hours (01 .....) 12)
%l hours (1 .....) 12)
%i minutes, Number (00 .....) 59)
%r time, 12 hours (Hh:mm:ss [ap]m)
%T time, 24 hours (HH:MM:SS)
%s seconds (00 ...). 59)
%s seconds (00 ...). 59)
%p am or PM
%w the number of days in one weeks (0=sunday ...). 6=saturday)
%u weeks (0 .....) 52), here Sunday is the first day of the week
%u weeks (0 .....) 52), here Monday is the first day of the week
Percent% of a text "%".
%a-a shorthand for the day of the week
%A-The full story of the week
%b-Abbreviations for months
%B-Full writing of the month
%c-Date Time 06/12/05 11:15:10
%c-century time
%d-one month ordinal (from 01 to 31)
%d-same%m/%d/%y
%e-What is the number of one months, the singular is preceded by a space (from 1 to 31)
%g-century
%G-century [0000,9999]
%h-Tong%b
Hours of%h-24 hours (from 00 to 23)
Hours of%i-12 hours (from 01 to 12)
%j-Days of the year (from 001 to 366)
%k-24 hours in the form of a single digit preceded by a space. (from 0 to 23)
%l-12 hours in the form of a single digit preceded by a space. (range 1 to 12)
%m-month (range to 12)
%m-min
%n-line Feed
%p-show morning or afternoon ' am ' or ' PM '
%R-A.M. or p.m. Form of Time
%r-24 hour form of time
%s-Sec
%t-tab symbol
%T-Tong%h:%m:%s
%u-use [1,7] to indicate the day of the week
%u-The calculation is the first few weeks of the year, starting from Sunday of the year
%V-calculated to be the first day of the year, from 01 to 53, the first week must have at least 4 days in this year, Sunday as this week
%w-in digital form is the day ordinal of the week, Sunday is 0
%w-in digital form is the first few weeks of the year, starting from Monday of the year
%x-Display Date: Month/day/year
%x-Display time: Hours: minutes: sec
%y-not including the year of the Century
%Y-including the year of the Century
%Z-time Zone
%%-Output%