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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Midnight three years ago 2

Status
Not open for further replies.

ter79

IS-IT--Management
Jul 11, 2001
106
0
0
US
Can someone help me with creating a dateadd statment that will return today's date three ago and at 11:59 PM

12/19/2002 23:59:59 is the final result

I have the syntax for the year part but not to get it to 23:59:59

Code:
SELECT DateAdd(yyyy, -3, CONVERT(smalldatetime, CONVERT(char(10), GETDATE(), 103), 103))
 
You need to use DateTime not SmallDateTime. Then, simply add 86399 seconds (because there are 86400 seconds in a day).

SELECT DateAdd(Second, 86399, DateAdd(yyyy, -3, CONVERT(datetime, CONVERT(char(10), GETDATE(), 103), 103)))

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Same thing, another way:
Code:
select dateadd(ss, -1, dateadd(yy, -3, dateadd(dd, datediff(dd, 0, getdate()), 1)))

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Thanks gmmastros and vongrunt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top