Tuesday, March 27, 2012

days in sql server

Is there any way to find out in sql server that whether it is Monday to friday or saturday sunday.
I have to write a stored procedure in which the logic shoukld be done only if there is a weekend.
if saturday or sunday
select * from status_temp

Please let me know if there is any function that is available in sql

Use DatePart(Weekday, GetDate())

Returns
1 for Sunday
2 for Monday
3 for Tuesday
4 for Wednesday and so on.

|||Hi,
You can also check "SET DATEFIRST" command and @.@.DATEFIRST parameter from BOL.
For US and English Sunday is the first day of week.
Eralper
|||You could also useDATENAME function:
SELECT someColumns FROM status_temp WHERE DATENAME(dw,yourDateTimeColumn) IN ('Saturday','Sunday')
I would guess that DATEPART would be faster, but DATENAME is easier to remember :-)
|||Thanks for all the responses.sql

No comments:

Post a Comment