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

subtract getdate

Status
Not open for further replies.

gtjr921

Programmer
Aug 30, 2006
115
How can I subtract one day from getdate() without it returning the time?
If i do select DateAdd(dayofyear,-1,GetDate())
then it goes back exactly 24 hours how can i get it to just go back one date and then I would do a where clause to compare that to another date whose time is all 00:00:00.000
I guess that could be converted somehow too.

Thanks!!
 
convert(varchar(10),dateadd(d,-1,getdate()),103)

Hope this helps
 
If you want to retain the field as a date type then you could use

SELECT DATEADD(dd, DATEDIFF(dd, 0, GETDATE() - 1), 0)

This is from one of the date conversion FAQs that you can view with the button near the top of the page


Geraint

The lights are on but nobody's home, my elevator doesn't go to the top. I'm not playing with a full deck, I've lost my marbles. Barenaked Ladies - Crazy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top