Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
T-SQL (SS2K5)
»
DatePart week and year end
DatePart week and year end
Rate Topic
Display Mode
Topic Options
Author
Message
pbaldy
pbaldy
Posted Wednesday, January 09, 2013 3:19 PM
Grasshopper
Group: General Forum Members
Last Login: Monday, January 28, 2013 10:35 AM
Points: 19,
Visits: 20
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
J Livingston SQL
J Livingston SQL
Posted Wednesday, January 09, 2013 3:26 PM
UDP Broadcaster
Group: General Forum Members
Last Login: Today @ 9:34 AM
Points: 1,451,
Visits: 14,224
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 !
__________________________________________________________________
Post #1405046
pbaldy
pbaldy
Posted Wednesday, January 09, 2013 3:41 PM
Grasshopper
Group: General Forum Members
Last Login: Monday, January 28, 2013 10:35 AM
Points: 19,
Visits: 20
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
J Livingston SQL
J Livingston SQL
Posted Wednesday, January 09, 2013 3:47 PM
UDP Broadcaster
Group: General Forum Members
Last Login: Today @ 9:34 AM
Points: 1,451,
Visits: 14,224
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 !
__________________________________________________________________
Post #1405059
anthony.green
anthony.green
Posted Thursday, January 10, 2013 2:13 AM
SSCertifiable
Group: General Forum Members
Last Login: Friday, April 12, 2013 3:51 AM
Points: 5,075,
Visits: 4,831
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
octagonbi
octagonbi
Posted Friday, January 11, 2013 2:00 PM
Forum 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 »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.