|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Today @ 2:00 AM
Points: 140,
Visits: 472
|
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Sunday, May 05, 2013 10:12 AM
Points: 480,
Visits: 1,604
|
|
In many cases, I can do what I have to do by simply capturing the weekday values for a known saturday and sunday, like so:
declare @dowSat int declare @dowSun int set @dowSat=datepart(dw,'20061028') set @dowSun=datepart(dw,'20061029')
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 10:57 PM
Points: 1,491,
Visits: 3,008
|
|
Nice tip, Divya. I'm adding this to my bookmarks next to that for "Some Common Date Routines" that Lynn Pettis put up a while ago.
--- Edit to correct link
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Today @ 2:00 AM
Points: 140,
Visits: 472
|
|
Yes Michael, that is certainly there. My post gives an idea of forthcoming weekends without having any intimation of dates.
--Divya
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Today @ 2:00 AM
Points: 140,
Visits: 472
|
|
Thanks John. I am not able to open Lynn Pettis post..
--Divya
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, July 19, 2011 10:39 PM
Points: 1,
Visits: 35
|
|
Good Article Divya....
This is Another way..
set datefirst 2 select datediff(dd,5,'12/17/2009')%7 set datefirst 5 select datediff(dd,5,'12/17/2009')%7
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Friday, April 05, 2013 3:42 AM
Points: 291,
Visits: 1,064
|
|
Excellent Article Divya..... Satnam
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, January 20, 2011 12:23 AM
Points: 5,
Visits: 27
|
|
This is a great tip. Thanks.
Can I raise a question regarding it though?
Maybe I'm misreading but if the date you pick is Saturday (instead of Thursday in the example - 17th Dec 2009 was a Thursday I believe), unless I'm very much mistaken by the values returned from modulo, the final result after applying the modulo will be zero. Seven needs to be added in this case.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 2:04 AM
Points: 1,968,
Visits: 1,819
|
|
This code is indipendent from datefirst: Monday is 0 and Sunday is 6 SELECT cast(cast('20100215' as datetime) as int)%7 SELECT cast(cast('20100216' as datetime) as int)%7 SELECT cast(cast('20100217' as datetime) as int)%7 SELECT cast(cast('20100218' as datetime) as int)%7 SELECT cast(cast('20100219' as datetime) as int)%7 SELECT cast(cast('20100220' as datetime) as int)%7 SELECT cast(cast('20100221' as datetime) as int)%7
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:26 PM
Points: 2,359,
Visits: 3,292
|
|
SELECT 1 + DATEDIFF(DAY, 0, '20091217') % 7
N 56°04'39.16" E 12°55'05.25"
|
|
|
|