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 |
|
EASYSQL
Starting Member
10 Posts |
Posted - 2006-04-03 : 14:36:47
|
| In the following query i want to get the orders for previous day and not the current day.I am unable to frame the date range for this, so i am leaving it blank.I tried so many ways but what i need is date starting from zero hrs yesterday till zero hrs today.I need report lying for the day before today.ThanksI have the following querySELECT O.work_order_id,O.LOAN_NUMBER,WEB_SUBMIT_DTFROM OA_EST_HDR A (NOLOCK)JOIN grasscutordercompletion B (NOLOCK) ON A.ORDER_ID = B.grasscutorderIDWHERE b.SUBMIT_STATUS = 0 AND O.ORDER_STATUS = 13and day(WEB_SUBMIT_DT) =I have the date in the following format "2004-01-28 08:49:00" |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-04-03 : 16:47:30
|
| Have a look at -- dateadd-- datedifffunctions.U r too close to the answer, so better u try urself.Srinika |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-04-03 : 19:33:39
|
[code]select dateadd(day, datediff(day, 0, getdate()), -1) as [0 hour yesterday], dateadd(day, datediff(day, 0, getdate()), 0) as [0 hour today][/code] KHChoice is an illusion, created between those with power, and those without. |
 |
|
|
EASYSQL
Starting Member
10 Posts |
Posted - 2006-04-03 : 21:47:43
|
| Thanks it worked great but when i use getdate() -1 and getdate() 0 its populating the dates 2006-04-02 00:00:00.0002006-04-02 00:00:00.0002006-04-03 00:00:00.0002006-04-03 00:00:00.000but when i just want for 1 past day i am using ord_date BETWEEN dateadd(day, datediff(day, 0, getdate()), -1) and dateadd(day, datediff(day, 0, getdate()), -1) so it gives me the date range,hope this is correct and it is what i wanted.2006-04-02 00:00:00.0002006-04-02 00:00:00.0002006-04-02 00:00:00.0002006-04-02 00:00:00.000 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-04-04 : 02:49:21
|
If you want to select only yesterday's orderwhere ord_date >= dateadd(day, datediff(day, 0, getdate()), -1)and ord_date < dateadd(day, datediff(day, 0, getdate()), 0) Note : BETWEEN is inclusive of both dateFrom Books Online on BETWEENquote: BETWEEN returns TRUE if the value of test_expression is greater than or equal to the value of begin_expression and less than or equal to the value of end_expression.
KHChoice is an illusion, created between those with power, and those without. |
 |
|
|
|
|
|
|
|