MySql查询选择具有特定日期的记录 [英] MySql query to select records with a particular date

查看:150
本文介绍了MySql查询选择具有特定日期的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以现在我正在这样存储我的网站上完成的每个搜索的日期

so right now I'm storing a the date of each search done on my site like this

2011-06-07 21:44:01

现在我想执行一个查询来选择所有的值日期等于任何,但仅考虑年/月和日,因此将如

now I'd like to execute a query to select all values where the date is equal to whatever, but only the year / month and day are taken into account, so it would be like

mysql_query("SELECT tag from tags WHERE date = '2011-06-07'");

但它不应该考虑确切的时间(小时分钟),有没有办法这样做?

but it shouldn't take into account the exact time (hour minute seconds), is there any way to do this?

推荐答案

你可以使用 DATE() 功能

You could use the DATE() function.

SELECT `tag`
  FROM `tags`
 WHERE DATE(`date`) = '2011-06-07'

然而,为了更好的表现,您可以使用...

However, for better performance you could use...

  WHERE `date` 
BETWEEN '2011-06-07'
    AND '2011-06-07 23:59:59'

这篇关于MySql查询选择具有特定日期的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆