Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date / Month

Author  Topic 

thehandsomecode
Yak Posting Veteran

51 Posts

Posted - 2007-06-18 : 14:50:48
I need to sort some data by month or extract data for a particular month. My date format is 5/7/2007 11:38:54 AM. What is the easiest way to achieve this?

Melvin Felicien
IT Manager
DCG Properties Limited

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-06-18 : 14:57:05
select * from table1
where col1 >= '20070701' and col1 < '20070801'


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

thehandsomecode
Yak Posting Veteran

51 Posts

Posted - 2007-06-18 : 15:00:35
thank you but i need to know how to sort it by month as well where it will list it in the following format?
January

Feburary

Etc

Melvin Felicien
IT Manager
DCG Properties Limited
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-06-18 : 15:03:15
select year(col1), datename(month, col1)
from table1
order by col1


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

thehandsomecode
Yak Posting Veteran

51 Posts

Posted - 2007-06-18 : 15:16:05
Thank you this works perfectly.

Melvin Felicien
IT Manager
DCG Properties Limited
Go to Top of Page
   

- Advertisement -