November 21, 2017 at 9:04 am
I need to run daily script to create a report.
How to code to find out data like below
select * from order where orderDateTime between ('getdate()-2 10:00 AM') and ('getdate()-1 5:00 PM')?
For example, today date in 2017-11-21
I need a report
between 2017-11-19 10:00 AM and 2017-11-20 5:00 PM
Tomorrow is 2017-11-22, I need a report
between 2017-11-20 10:00 AM and 2017-11-21 5:00 PM
I tried to use DATEADD but don't know how to use it for time.
November 21, 2017 at 9:12 am
WHERE orderDateTime
BETWEEN DATEADD(hour, 10, DATEADD(day, DATEDIFF(day, 2, CURRENT_TIMESTAMP), 0))
AND DATEADD(hour, 17, DATEADD(day, DATEDIFF(day, 1, CURRENT_TIMESTAMP), 0))
November 21, 2017 at 9:15 am
adonetok - Tuesday, November 21, 2017 9:04 AMI need to run daily script to create a report.
How to code to find out data like below
select * from order where orderDateTime between ('getdate()-2 10:00 AM') and ('getdate()-1 5:00 PM')?
For example, today date in 2017-11-21
I need a report
between 2017-11-19 10:00 AM and 2017-11-20 5:00 PM
Tomorrow is 2017-11-22, I need a report
between 2017-11-20 10:00 AM and 2017-11-21 5:00 PM
I tried to use DATEADD but don't know how to use it for time.
DECLARE @testdate DATETIME;
November 21, 2017 at 9:54 am
Thanks, two scripts are all work great!
November 21, 2017 at 10:43 am
November 21, 2017 at 11:41 am
I printed it and pinned it.
Thank you again.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply