Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2005 Date Time stamp Query

One of my columns type is DateTime (Date Registered). I cannot create a query that filters all the data for eg. All registrations who registered on the 22/10/2008 between 18:00 and 20:00.

Thanks

like image 223
David Bonnici Avatar asked Dec 10 '08 19:12

David Bonnici


People also ask

How do I get the current TIMESTAMP in SQL query?

The CURRENT_TIMESTAMP function returns the current date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format. Tip: Also look at the GETDATE() function.

How do I date a TIMESTAMP in SQL?

SQL Date Data Types DATE - format YYYY-MM-DD. DATETIME - format: YYYY-MM-DD HH:MI:SS. TIMESTAMP - format: YYYY-MM-DD HH:MI:SS. YEAR - format YYYY or YY.


2 Answers

SELECT *
FROM YourTable
WHERE DateRegistered BETWEEN '10/22/2008 18:00:00' AND '10/22/2008 20:00:00'

Should do the trick

like image 54
Mitchel Sellers Avatar answered Sep 21 '22 01:09

Mitchel Sellers


have you tried using datediff?

http://msdn.microsoft.com/en-us/library/ms189794.aspx

like image 25
Victor Avatar answered Sep 21 '22 01:09

Victor