August 30, 2013 at 10:34 am
I want to add a condition for date time range of yesterday 3pm . Basically I want to write something like below
SELECT * FROM abc
WHERE DATETIME between 'Yesterday 3pm' and 'Today 2:59pm'
Please help me to add the date time code for the above time range .
August 30, 2013 at 11:56 am
Something like this?
select dateadd(hour, 15, dateadd(dd, datediff(dd, 0, GETDATE()) - 1, 0)),
dateadd(minute, 899, dateadd(dd, datediff(dd, 0, GETDATE()), 0))
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
August 30, 2013 at 12:22 pm
Aboslutely , thanks alot Sean !
August 30, 2013 at 12:28 pm
Something like this:
SELECT
*
FROM
abc
WHERE
DateCol >= dateadd(hour, 15, dateadd(day, datediff(day, 0, getdate()), -1)) and
DateCol < dateadd(hour, 15, dateadd(day, datediff(day, 0, getdate()), 0))
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply