Mega Code Archive

 
Categories / Delphi / Examples
 

Extracting the month of a date

Question: My table has a field LastMod of type DATE which contains the last time the record was modified. Now I'd like to group records by the month they were modified. How can I elegantly extract the month from a DATE field? Answer: Use the EXTRACT() function. The syntax is: EXTRACT(modifier FROM fieldname) where modifier can be: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, WEEKDAY, YEARDAY. Example: select EXTRACT(MONTH from LastMod) from TableName