MySQL EXTRACT Function
Example Extract the month from a date: SELECT EXTRACT(MONTH FROM “2017-06-15”); Definition and Usage The EXTRACT() function extracts a part from a given date.
Example Extract the month from a date: SELECT EXTRACT(MONTH FROM “2017-06-15”); Definition and Usage The EXTRACT() function extracts a part from a given date.
Example Return the day of the year for a date: SELECT DAYOFYEAR(“2017-06-15”); Definition and Usage The DAYOFYEAR() function returns the day of the year for a given date (a number from 1 to 366).
Example Return the weekday index for a date: SELECT DAYOFWEEK(“2017-06-15”); Definition and Usage The DAYOFWEEK() function returns the weekday index for a given date (a number from 1 to 7). Note: 1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, 6=Friday, 7=Saturday.
Example Return the day of the month for a date: SELECT DAYOFMONTH(“2017-06-15”); Definition and Usage The DAYOFMONTH() function returns the day of the month for a given date (a number from 1 to 31).
Example Return the weekday name for a date: SELECT DAYNAME(“2017-06-15”); Definition and Usage The DAYNAME() function returns the weekday name for a given date.
Example Return the day of the month for a date: SELECT DAY(“2017-06-15”); Definition and Usage The DAY() function returns the day of the month for a given date (a number from 1 to 31).
Example Subtract 10 days from a date and return the date: SELECT DATE_SUB(“2017-06-15”, INTERVAL 10 DAY); Definition and Usage The DATE_SUB() function subtracts a time/date interval from a date and then returns the date.
Example Format a date: SELECT DATE_FORMAT(“2017-06-15”, “%Y”); Definition and Usage The DATE_FORMAT() function formats a date as specified.
Example Add 10 days to a date and return the date: SELECT DATE_ADD(“2017-06-15”, INTERVAL 10 DAY); Definition and Usage The DATE_ADD() function adds a time/date interval to a date and then returns the date.