The following query:
SELECT * FROM `objects`
WHERE (date_field BETWEEN \'2010-09-29 10:15:55\' AND \'2010-01-30 14:15:55\')
returns nothin
Your second date is before your first date (ie. you are querying between September 29 2010 and January 30 2010). Try reversing the order of the dates:
SELECT *
FROM `objects`
WHERE (date_field BETWEEN '2010-01-30 14:15:55' AND '2010-09-29 10:15:55')
Your query should have date as
select * from table between `lowerdate` and `upperdate`
try
SELECT * FROM `objects`
WHERE (date_field BETWEEN '2010-01-30 14:15:55' AND '2010-09-29 10:15:55')
When using Date and Time values, you must cast the fields as DateTime
and not Date
.
Try :
SELECT * FROM `objects`
WHERE (CAST(date_field AS DATETIME)
BETWEEN CAST('2010-09-29 10:15:55' AS DATETIME) AND CAST('2010-01-30 14:15:55' AS DATETIME))
Might be a problem with date configuration on server side or on client side. I've found this to be a common problem on multiple databases when the host is configured in spanish, french or whatever... that could affect the format dd/mm/yyyy or mm/dd/yyyy.
Is date_field
of type datetime
? Also you need to put the eariler date first.
It should be:
SELECT * FROM `objects`
WHERE (date_field BETWEEN '2010-01-30 14:15:55' AND '2010-09-29 10:15:55')
DATE() is a MySQL function that extracts only the date part of a date or date/time expression
SELECT * FROM table_name WHERE DATE(date_field) BETWEEN '2016-12-01' AND '2016-12-10';