Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write a SQL query for a specific date range and date time using SQL Server 2008?

I need to write a query that will get all the rows in a specified date range and time range.

For example, I want to query all the rows from 5:00PM on 16-Sep-2010 to 9:00AM on 21-Sep-2010.

Any ideas as to how the query should be?

like image 380
Zubair Avatar asked Sep 21 '10 13:09

Zubair


People also ask

How do you write a date range in SQL query?

SELECT * FROM PERSONAL WHERE BIRTH_DATE_TIME BETWEEN '2000-01-01 00:00:00' AND '2002-09-18 12:00:00';

How do I find data for a specific date in SQL?

You just need to tell the processor what format the date/time is in: Select * from Table where date Between to_date('2009-05-24 06:15:00', 'yyyy-mm-dd hh24:mi:ss') and to_date('2009-05-24 08:15:00 ', 'yyyy-mm-dd hh24:mi:ss').

How do I select data between two dates in SQL Server?

SELECT * FROM ATM WHERE TRANSACTION_TIME BETWEEN '2005-02-28 21:00:00' AND '2008-12-25 00:00:00';


1 Answers

SELECT * FROM TABLE
WHERE DATE BETWEEN '09/16/2010 05:00:00' and '09/21/2010 09:00:00'
like image 187
bahadir arslan Avatar answered Oct 11 '22 10:10

bahadir arslan