Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Increment week function starts on Sunday

Status
Not open for further replies.

dibbo

Programmer
Nov 22, 2004
12
GB
Hi, i've got the following code in a query:

DATEADD(wk, DATEDIFF(wk, 0, SH_StartDateTime), 0)

it works ok in the way that it returns:
08/11/2004
08/11/2004
08/11/2004
15/11/2004
15/11/2004
15/11/2004
22/11/2004
and so on....
The 8th, 15th and 22nd being Monday's

But for some reason it's including all SH_StartDateTime from the day before aswell i.e. Sunday.
so the actual data grouping is Sun-Sat instead of Mon-Sun

Any ideas on how to solve this?

Many Thanks

David
 
sorted..

replaced SH_StartDateTime with DATEADD(d,-1,SH_StartDateTime)
 
Code:
[Blue]SET[/Blue] [Black]DateFirst[/Black] 1
[Blue]SELECT[/Blue] [Fuchsia]DateAdd[/Fuchsia][Gray]([/Gray]wk[Gray],[/Gray] [Fuchsia]DateDiff[/Fuchsia][Gray]([/Gray]wk[Gray],[/Gray] 0[Gray],[/Gray] SH_StartDateTime[Gray])[/Gray][Gray],[/Gray] 0[Gray])[/Gray]
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top