[英]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(c.id) 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 我的约会时间戳是这样的:2016-09-07 21:04:46
For some reason this does not return any records, why? 由于某种原因,它不返回任何记录,为什么?
Change the following line: 更改以下行:
AND date_format(c.created, 'Y-m-d') between '2016-09-06' AND '2016-09-07'
to 至
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. date()函数将从datetime返回日期,并将检查给定范围。
use date() function instead of date_format() 使用date()函数代替date_format()
SELECT count(c.id) as totalOrders
FROM Cart c
WHERE c.artist_id = 1
AND c.paid = 1
AND date(c.created) between '2016-09-06' AND '2016-09-07'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.