August 16, 2005 at 9:27 am
When I run the following script:
declare @d datetime
set DATEFIRST 1 --first day of the week is sunday, monday is 2 etc etc
select @d = '3/31/2005'
select @d
select datepart(dw, @d)
select datename(dw, @d)
I get :
4
Thursday
But I thought Thursday was number 5 ??????
can anyone explain
August 16, 2005 at 9:58 am
According to BOL, Monday is 1, so the results you're getting are correct.
Value | First day of the week is |
---|---|
1 | Monday |
2 | Tuesday |
3 | Wednesday |
4 | Thursday |
5 | Friday |
6 | Saturday |
7 (default, U.S. English) | Sunday |
If you want Thursday to be 5, then SET DATEFIRST 7 (Making Sunday the first day of the week)
August 16, 2005 at 10:00 am
SET DATEFIRST 1 makes Monday the first day of the week. SET DATEFIRST 7 makes Sunday the first day of the week.
From BOL:
Sets the first day of the week to a number from 1 through 7.
SET DATEFIRST { number | @number_var }
number | @number_var
Is an integer indicating the first day of the week, and can be one of these values.
Value | First day of the week is |
---|---|
1 | Monday |
2 | Tuesday |
3 | Wednesday |
4 | Thursday |
5 | Friday |
6 | Saturday |
7 (default, U.S. English) | Sunday |
Greg
Greg
August 16, 2005 at 10:39 am
thanks.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply