Definition and usage
The date_format () function is used to display date/time data in different formats.
Syntax
Date_format (date, Format)
The date parameter is a valid date. Format specifies the output format of the date/time.
The following formats are available:
Format description
% A abbreviated name for a week
% B abbreviated month name
% C month, numeric value
% D the day of the month with an English prefix
Day of % d month, value (00-31)
% E day (0-31)
% F microseconds
% H hour (00-23)
% H hour (01-12)
% I hour (01-12)
% I minutes, numeric value (00-59)
% J-day (001-366)
% K hour (0-23)
% L hour (1-12)
% M month name
% M month, value (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) Sunday is the first day of the week
% U Week (00-53) Monday is the first day of the week
% V Week (01-53) Sunday is the first day of the week, used with % x
% V Week (01-53) Monday is the first day of the week, used with % x
% W week name
% W Day (0 = Sunday, 6 = Saturday)
% X, where Sunday is the first day of the week, 4 digits, used with % v
% X, where Monday is the first day of the week, 4 digits, used with % v
% Y year, 4 digits
% Y years, two places
Instance
The following script uses the date_format () function to display different formats. Now () is used to obtain the current date/time:
Date_format (now (), '% B % d % Y % H: % I % p ')
Date_format (now (), '% m-% d-% y ')
Date_format (now (), '% d % B % y ')
Date_format (now (), '% d % B % Y % T: % F ')
The result is similar:
Dec 29 2008 pm
12-29-2008
29 Dec 08
29 Dec 2008 16:25:46. 635