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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 UDF

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2005-08-08 : 22:49:49
How can I write a UDF that returns day of the week?
For example, '20050808' returns 'Monday'..


timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2005-08-08 : 23:00:27
You can use the DATEPART function.
DATEPART(w, dat)

from memory.....

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-09 : 01:27:30
Something like

declare @d int
declare @day varchar(10)

select @d=datepart(w,'20050808')


Select @day=
Case when @d=1 then 'Sunday'
when @d=2 then 'Monday'
.
.

end

Return @day


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -