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
 SQL Server Development (2000)
 date

Author  Topic 

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2004-09-27 : 10:40:01
Hi,
How do you find the day of the week in sql please?
Thanks

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2004-09-27 : 10:41:16
look up DATEPART() in BOL...
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-09-27 : 10:55:42
I'm Suprised DATEPART doesn't do this...


CREATE FUNCTION udf_WeekDay(@x datetime)
RETURNS varchar(9)
AS
BEGIN
RETURN (
SELECT
CASE DATEPART(dw,@x)
WHEN 1 THEN 'Sunday'
WHEN 2 THEN 'Monday'
WHEN 3 THEN 'Tuesday'
WHEN 4 THEN 'Wednesday'
WHEN 5 THEN 'Thurday'
WHEN 6 THEN 'Friday'
WHEN 7 THEN 'Satday'
END)
END
GO

SELECT dbo.udf_WeekDay(GetDate())
GO




Brett

8-)
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2004-09-27 : 10:59:21
Ooppps, I should have said DATENAME(dw,getdate())...
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-09-27 : 11:10:52
Damn...I never used that...why wouldn't they just roll all of that in to 1 function I wonder....



Brett

8-)
Go to Top of Page
   

- Advertisement -