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
 Distinct Days in a set of dates

Author  Topic 

anumodhc
Starting Member

13 Posts

Posted - 2009-07-07 : 09:37:58
Hi

I have a set of Dates in a date period. Have to get distinct Days like
"Su,Mo,Tu,We,Th,Fr,Sa" or like "1,2,3,4,5,6,7" from that.Please help.
Thanks in advance

AnumodH

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-07 : 09:45:31
use datepart(weekday, [date period])

or

datename(weekday, [date period])


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

anumodhc
Starting Member

13 Posts

Posted - 2009-07-08 : 00:45:29
In my case i have a set of date values like 01/06/2009,01/13/2009,
01/20/2009,01/27/2009,02/03/2009,02/10/2009,02/17/2009,02/24/2009.

All these dates are Thursdays.

I need a function to which i will pass these set of date values, and it should return only "Th" or "5"

If more days, then it should return like "Mo,Th".

Please help

AnumodH
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-08 : 00:51:01
the set of date value is in a string ? or table ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

anumodhc
Starting Member

13 Posts

Posted - 2009-07-08 : 00:59:47
date values are in table.
I can make it as a string also

AnumodH
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-08 : 01:04:45
it is easier to do in table

-- Date value in table

select left(datename(weekday, datecol), 2) as Weekday_Name
from table

select datepart(weekday, datecol) as Weekday_No
from table


if it is in a CSV string, you need to parse the string, convert then form the CSV again.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

anumodhc
Starting Member

13 Posts

Posted - 2009-07-08 : 01:07:08
Thanks a lot friend

AnumodH
Go to Top of Page
   

- Advertisement -