cevans
Junior Member
 
Canada
101 Posts |
Posted - 28 June 2001 : 09:47:16
|
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 |
 |
|