Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sqlserverdeveloper
Posting Yak Master
243 Posts |
Posted - 2009-03-02 : 17:13:36
|
| I am trying to extract data for the orders created the previous day from the table:select * from orders twhere t.orderdate >= Prevday 12:00AM and t.orderdate <= Prevday 11:59:59PM orderdate is datetime datatype, Please advice, how can I format the date to show as:Prevday 12:00AM and Prevday 11:59:59PMThanks! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sqlserverdeveloper
Posting Yak Master
243 Posts |
Posted - 2009-03-02 : 18:17:02
|
| Thanks for the quick response.Select DATEADD(Day, DATEDIFF(Day, 0, GetDate()), 0) is returning 2009-03-02 00:00:00.000, since I am looking for2009-03-01 11:59:59PM(prev day), so are both the same? Is it okay if I use 2009-03-02 00:00:00.000.Thanks! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-03-02 : 23:24:45
|
| try like thiswhere dateadd(dd,datediff(d,0,date),0) = dateadd(dd,datediff(dd,0,getdate()-1),0) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-03 : 09:51:00
|
quote: Originally posted by bklr try like thiswhere dateadd(dd,datediff(d,0,date),0) = dateadd(dd,datediff(dd,0,getdate()-1),0)
this will cause index to be ignored if present in date column |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-03-03 : 09:53:47
|
He will never stop suggeting that.It's not the first time, neither here nor on other forums. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|
|
|