Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1
%y
Year—2
digit
%j
Day of the
year—
numeric

%a (^) Abbreviated
weekday
name
%d (^) Day of the
month—
digit
%r
Time—12
hour clock
%T (^) Time—24
hour clock
%H (^) Hour 00-23
%h
Hour 01-12
%"i"
Minutes 00-
59
%S
Seconds
Example:
SELECT DATE_FORMAT('2000-02-27', '%M %D %Y')
Result:
February 27th 2000


DATE_SUB(date, INTERVAL value Type) and SUBDATE(date,


INTERVAL value Type)


Subtracts the value from the date argument. The word INTERVAL is a keyword and must be used in the
function. See ADDDATE() for the types and related values.
Example:
SELECT DATE_SUB(2000-01-01, INTERVAL 1 DAY)
Result:


1999-12-31
Example:
SELECT DATE_SUB(2000-03-10 00:00:00, INTERVAL 1 MINUTE)
Result:

2000-03-09 23:59:00

DAYNAME(date)


Returns the name of the day given in date.
Example:
SELECT DAYNAME('2000-01-27')
Results:


"Thursday"

DAYOFMONTH(date)


Returns the day of the month given in the date argument.
Example:
SELECT DAYOFMONTH('2000-01-27')
Result:

Free download pdf