我正在尝试查询记录。日期存储为日期时间戳,我的查询如下所示:
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'
我的日期时间戳是这样的:2016-09-07 21:04:46
出于某种原因,这不会返回任何记录,为什么?
答案 0 :(得分:1)
更改以下行:
html
head
title Registration Form
body
ul
each post in posts
form(action='', method='POST')
label(for='post[email]') Email:
input(type='text', name="post[_id]", value=post._id)
br
label(for='post[name]') Name:
input(type='text', name="post[name]", value=post.name)
br
label(for='post[age]') Age:
input(type='text', name="post[age]", value=post.age)
br
input(type='submit')
到
AND date_format(c.created, 'Y-m-d') between '2016-09-06' AND '2016-09-07'
date()函数将从datetime返回日期,并将检查给定范围。
答案 1 :(得分:1)
使用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'