Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Dates - Please Help a Newbie
 New Topic  Topic Locked
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 2

cevans
Junior Member

Canada
101 Posts

Posted - 28 June 2001 :  09:47:16  Show Profile  Send cevans an ICQ Message
quote:

when i change it from "CONVERT (char(20), GETDATE(), 101)" to "CONVERT (char(20), GETDATE() - 1, 101)" to get all records with yesterday's date, it returns one less record than it should.



Try using convert(varchar(20),dateadd(d,-1,getdate()),101) instead.

This will first subtract 1 day from getdate() (using the dateadd function), then will strip off the time by converting the result to a varchar using formatting style 101 (mm/dd/yyyy). Note that you can choose from different date formats simply by changing the style parameter. See here in the MSDN Library for more info.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_2f3o.asp

Notice also that I'm converting to varchar (arguably a little more efficient) instead of char. As well, when converting to varchar, you don't have to specify a size (though you can if you want to. If you don't specify a size, I think it defaults to varchar(40), but I'm not positive.


Clark
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Previous Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.53 seconds. Powered By: Snitz Forums 2000 Version 3.4.07