Re: How do I always return Sunday of previous week. Sun - Sat.
From: Uri Dimant (urid_at_iscar.co.il)
Date: 08/10/04
- Next message: Uri Dimant: "Re: Shipping the most current scheduled job logs"
- Previous message: John Bell: "RE: Shipping the most current scheduled job logs"
- In reply to: Lam Nguyen: "How do I always return Sunday of previous week. Sun - Sat."
- Next in thread: John Gilson: "Re: How do I always return Sunday of previous week. Sun - Sat."
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 10 Aug 2004 10:27:02 +0200
Lam
declare @dt as datetime
set @dt='20040823'
select dateadd(day,datediff(day,'19000101',@dt)/7*7-1,'19000101')
"Lam Nguyen" <nguyen.lam@aaa-calif.com> wrote in message
news:2d4001c47e5b$875bf190$a301280a@phx.gbl...
> How do I get the previous Sun. Example if today Monday
> then I should previous week from Sun 8/1 - 8/7 Sat.
> The week start on Sunday and end on Sat of previous week.
> Thanks in advance.
>
> DECLARE @cDate DATETIME,
> @prevMonday DATETIME,
> @prevSunday DATETIME,
> @prevSat DATETIME
> SET @cDate = GETDATE()
> SELECT @cDate AS 'CurrentDate'
> --SET DATEFIRST 1
> SET @prevSunday = DATEADD(DAY , (-1 * DATEPART(dw,
> (@cDate - 1))), @cDate)
> SELECT @prevSat = CONVERT(CHAR(10), DATEADD(DAY, (0 -
> DATEPART(dw, CURRENT_TIMESTAMP )), CURRENT_TIMESTAMP), 101)
> SELECT @prevSunday AS 'PrevSunday', @prevSat AS 'PrevSat'
> GO
>
> Lam
- Next message: Uri Dimant: "Re: Shipping the most current scheduled job logs"
- Previous message: John Bell: "RE: Shipping the most current scheduled job logs"
- In reply to: Lam Nguyen: "How do I always return Sunday of previous week. Sun - Sat."
- Next in thread: John Gilson: "Re: How do I always return Sunday of previous week. Sun - Sat."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|