0

range of datetime data type (show all records in between 2 dates. example: form
2008/10/01 to 2008./12/12). thanks

5
Contributors
6
Replies
7
Views
9 Years
Discussion Span
Last Post by Shanti C
0

If the data type is datetime, then you must include time in the query

SELECT * FROM table where date_col BETWEEN '2008-10-01 00-00-00' AND '2008-12-12 23:59:59'
0

I need help please with a similar issue but in my case I don't want a specific date.

I need to query all records created yesterday.

Since the get date function only finds records with the exact minute and second I need to use a range. Less than current date but greater than 23 hours 59 minutes old.

How can I write this query please?

THank you

Matthew

If the data type is datetime, then you must include time in the query

SELECT * FROM table where date_col BETWEEN '2008-10-01 00-00-00' AND '2008-12-12 23:59:59'
0

Thank you very much for your help.

I was able to solve it in fact with datediff(date_col,getdate()) = -1

We are running mssql

Best regards,

Matthew

SELECT * FROM table WHERE date_col<curdate() and date>DATE_ADD(CURDATE(), INTERVAL -1 DAY)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.