DelphiFAQ Home Search:

Extracting the Month of a Date

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

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


Content-type: text/html

Comments:

2006-02-14, 02:18:17
anonymous from Greece  
When I use the above syntax (select EXTRACT(MONTH from LastMod) from TableName in Interbase 5.0 I receive the following error 'General SQL error. Token unknown - line 1, char 21 from'
2006-02-14, 02:19:10
geopat@teiser.gr from Greece  
When I use the above syntax (select EXTRACT(MONTH from LastMod) from TableName in Interbase 5.0 I receive the following error 'General SQL error. Token unknown - line 1, char 21 from'

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: