LargeTuna LargeTuna - 1 year ago 73
MySQL Question

PHP & MySQL query date time stamp between

I am attempting to query for a record. The date is stored as a date time stamp and my query looks like this:

SELECT count( as totalOrders
FROM Cart c
WHERE c.artist_id = 1
AND c.paid = 1
AND date_format(c.created, 'Y-m-d') between '2016-09-06' AND '2016-09-07'

My date time stamp is this: 2016-09-07 21:04:46

For some reason this does not return any records, why?

Answer Source

Change the following line:

AND date_format(c.created, 'Y-m-d') between '2016-09-06' AND '2016-09-07'


AND date(created) between '2016-09-06' AND '2016-09-07'

date() function will return the date from datetime and it will check in the given range.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download