July 10, 2008 at 11:59 am
In search of T-SQL which will accomplish this: Given "any" date, tell me if this is a SUNDAY.
Example:
Declare @mydate datetime
Select @mydate = (Select getdate())
IF @mydate = 'Sunday' .....
thx in advance
July 10, 2008 at 12:06 pm
use Datepart and be sure you know what your datefirst setting is. You can set any day to be the first day of the week.
I think you can also get the day name with datepart as well.
July 10, 2008 at 12:38 pm
when you use datepart and dw as the argument, it returns the weekday as integer value. where
Sunday=1 and Saturday=7 as mentioned in BOL. I hope the below query helps.
Declare @mydate datetime
Select @mydate = (Select getdate())
select datepart(dw,@mydate)
IF (datepart(dw,@mydate) = 1)
SELECT 'ITS A SUNDAY'
else
SELECT 'IT IS NOT A SUNDAY'
July 10, 2008 at 12:40 pm
hmmm -- isn't your repsonse analagous to something like this:
Do you have a recipe for a chocolate cake?
Yes, mix ingrediants and cook it. hahahaha (need specifics and preferrably an example please)
I'm trying to leverage an experts T-SQL experience - where they may have this in their toolkit already.
July 10, 2008 at 12:40 pm
if datename(weekday, getdate()) = 'Sunday'
July 10, 2008 at 12:47 pm
thanks Grasshopper -- I modified your code to look like this:
DECLARE@CheckDate DATETIME, @DayOfWeek SMALLINT
SELECT @CheckDate = '2008-07-06 00:00:00.000'
SELECT @DayOfWeek = (SELECT datepart(weekday, @CheckDate))
SELECT @DayOfWeek As TheDay
-- 1=Sunday
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply