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
 Year part from a date and time

Author  Topic 

shajimanjeri
Posting Yak Master

179 Posts

Posted - 2006-11-09 : 03:25:54
Hi,
I have a table with field Msg_Time. In this field some records are there with date and time.

For eg:-
11/7/2006 2:35:00 AM,
11/1/2006 2:35:00 AM,
10/15/2006 2:35:00 AM,
11/7/2005 2:35:00 AM,
11/7/2005 2:35:00 AM,
8/26/2005 2:35:00 AM,
3/2/2005 2:35:00 AM etc

I wrote the query like this
"select datepart(year, Msg_Time) from C20_Messages"
This query result is:-
2006
2006
2006
2005
2005
2005
2005
Here I want to get only the year part without repeating.
I mean
2005
2006

How to do pls help me
with regards
shaji

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-09 : 03:27:05
select DISTINCTdatepart(year, Msg_Time) from C20_Messages
order by datepart(year, Msg_Time)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

shajimanjeri
Posting Yak Master

179 Posts

Posted - 2006-11-09 : 03:33:03

Dear Peter Larsson,

Thanx a lot. Its working...fine

Shaji

quote:
Originally posted by Peso

select DISTINCTdatepart(year, Msg_Time) from C20_Messages
order by datepart(year, Msg_Time)


Peter Larsson
Helsingborg, Sweden



Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-09 : 04:24:37
you can also use

year(Msg_Time)


KH

Go to Top of Page
   

- Advertisement -