Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

DatePart week and year end Expand / Collapse
Author
Message
Posted Wednesday, January 9, 2013 3:19 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, April 24, 2014 10:40 AM
Points: 35, Visits: 50
I have this in a stored procedure (SS2005):

DATEPART(ww,Driver_summary.Dor_date) AS WeekNum

When run for a period of 12/30/12 through 1/5/13, it is returning 53 for the days in 2012 and 1 for the days in 2013. Is there a way to get the function to return the same week number for any given Sunday-Saturday time frame, regardless of whether it falls over a year end?

Thanks,

Paul



Post #1405044
Posted Wednesday, January 9, 2013 3:26 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 2:48 PM
Points: 1,932, Visits: 19,917
suggest you search this site (and others) for "Calendar tables"....

weeks are generally peculiar to the industry/company...there is a lot of help out there if you care to read.

regards


______________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
Post #1405046
Posted Wednesday, January 9, 2013 3:41 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, April 24, 2014 10:40 AM
Points: 35, Visits: 50
I appreciate your quick reply. I will do that research. The DatePart() function in Access has arguments that let you control this (specifically the "firstweekofyear" argument). I had hoped SQL Server's did as well and I was just missing it.


Post #1405054
Posted Wednesday, January 9, 2013 3:47 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 2:48 PM
Points: 1,932, Visits: 19,917
pbaldy (1/9/2013)
I appreciate your quick reply. I will do that research. The DatePart() function in Access has arguments that let you control this (specifically the "firstweekofyear" argument). I had hoped SQL Server's did as well and I was just missing it.


try this for a start

http://www.sqlservercentral.com/blogs/lynnpettis/2009/03/25/some-common-date-routines/


______________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
Post #1405059
Posted Thursday, January 10, 2013 2:13 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, November 1, 2014 6:54 AM
Points: 5,221, Visits: 5,118
This calendar table might also help you out

http://www.sqlservercentral.com/scripts/Date/68389/




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1405278
Posted Friday, January 11, 2013 2:00 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, January 22, 2013 2:41 PM
Points: 1, Visits: 5
I just came across this and created a case statement to get around this.

CASE WHEN DATEPART(ww,Driver_summary.Dor_date)=53 THEN 1 ELSE DATEPART(ww,Driver_summary.Dor_date) END AS WeekNum
Post #1406254
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse