This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Specific Time Range Query in SQL Server
For example I have 3 rows:
Id Date
1 '2011-01-02 09:14:23.0000000'
2 '2011-02-15 10:15:47.0000000'
3 '2011-03-18 21:12:33.0000000'
And I whant to take only rows, where TIME between 09:00 and 11:00 and any date.
I need this in result set:
Id Date
1 '2011-01-02 09:14:23.0000000'
2 '2011-02-15 10:15:47.0000000'
Thanks
Here's one approach
SELECT id, date
FROM myTable
WHERE CONVERT(VARCHAR(8),Date,108) between '09:00:00' and '11:00:00'
Related
This question already has an answer here:
Oracle SQL Where clause to find date records older than 30 days
(1 answer)
Closed 2 years ago.
I want to get an ORACLE statement which returns rows that are older than 30 days from the the date of creation.
My table has a field "date_entered" that contains the date and the time it was inserted in the database .
Thanks,
your select statement
WHERE date_entered < TRUNC(SYSDATE)-30
This question already has an answer here:
SQL Server Management Studio make default date 5 days from now
(1 answer)
Closed 4 years ago.
I need to create a view everyday with all records reaching the "Prazo" date ('Prazo' stands for due date in Portuguese), so everyday I need to make a select showing all the records that are 5 days from reaching the due date. How can I do that?
You can do:
Select *
from Table as t
Where DATEDIFF(DD, GETDATE(), PrazoDate) = 5
It just says how many records from today are 5 days from reaching their due date.
This question already has answers here:
Get records 10 min before system datetime in SQL
(4 answers)
Closed 6 years ago.
How can I substract the column "begin_execution" with 5 minutes?
The begin_execution-Datetime will filled via an SQL-Task, but i need this time -5 minutes to check the running compatibility.
Example:
SELECT * FROM queue_entry WHERE begin_execution - GETDATE()-5min AND STATUS = 'not solved'
Thats the original output:
2016-06-09 15:00:11.4070000
i need this output (-5 minutes):
2016-06-09 14:55:11.4070000
WHERE begin_execution >= DATEADD(MINUTE, -5, GETDATE())
This question already has answers here:
SQL: Get records created in time range for specific dates
(3 answers)
Closed 8 years ago.
I have a table with the field ENTERED_ON (with both date and time value). I want to write a query that return records that have ENTERED_ON value that is past 2 hours comparing to current date time.
For example, if entered_on is 2014-05-06 11:00AM, and currently it's 2014-05-06 2:00PM, I would like to return all records that past the 2 hours when comparing to current date time.
You can write query using INTERVAL. It will looks like
SELECT * FROM Table WHERE `ENTERED_ON` > DATE_ADD(NOW(), INTERVAL -2 HOUR)
This question already has an answer here:
How can I determine in SQL Server if a dateTime range overlaps another
(1 answer)
Closed 9 years ago.
I have a table which has two columns FromDate and ToDate.
Eg.
ID From Date To Date
1 2012-01-02 2012-01-07
2 2012-01-08 2012-01-14
3 2012-01-15 2012-01-21
4 2012-01-22 2012-01-28
What I am trying to do is when I pass new From and To dates, to check against this table to if the new date range fall under any of this dates finding the associate ID value. (I am not passing the exact from and Todate values which are already in the table)
For example if I pass 2012/01/25 as From and 2012/02/03 as To Date it should return 4.
I am not quite sure how to approach this problem.
Any help ?
Thanks
SELECT
*
FROM
yourTable
WHERE
to_date >= #from_date_parameter
AND from_date <= #to_date_parameter
SELECT ID FROM MyTable
WHERE FromDate<= '2012/02/03' AND ToDate>= '2012/01/25'
See this SQLFiddle