For a description of the range of values owned by each type and the valid format for the specified date and time value, see 7.3.6 Date and Time type.
Here is an example of using a date function. The following query selects all records and its date_col value is within the last 30 days:
Mysql> SELECT something from table
WHERE To_days (now ())-To_days (Date_col) <= 30;
DayOfWeek (date)
Returns the week index of date (1= Sunday, 2 = Monday, ...). 7= Saturday). These index values correspond to ODBC standards.
Mysql> Select DayOfWeek (' 1998-02-03 ');
-> 3
Weekday (date)
Returns the week index of date (0= Monday, 1 = Tuesday, ...). 6= Sunday).
Mysql> Select Weekday (' 1997-10-04 22:23:00 ');
-> 5
Mysql> Select Weekday (' 1997-11-05 ');
-> 2
DayOfMonth (date)
Returns the date in the month of date, in the range 1 through 31.
Mysql> Select DayOfMonth (' 1998-02-03 ');
-> 3
DayOfYear (date)
Returns the number of days in a year, in the range of 1 to 366.
Mysql> Select DayOfYear (' 1998-02-03 ');
-> 34
MONTH (date)
Returns the month of date, ranging from 1 to 12.
Mysql> Select MONTH (' 1998-02-03 ');
-> 2
Dayname (date)
Returns the name of the week of date.
Mysql> Select Dayname ("1998-02-05");
-> ' Thursday '
MonthName (date)
Returns the month name of the date.
Mysql> Select MonthName ("1998-02-05");
-> ' February '
Quarter (date)
Returns the quarter of date one year, ranging from 1 to 4.
Mysql> Select quarter (' 98-04-01 ');
-> 2
WEEK (date)
WEEK (Date,first)