mysql日期和日期时间问题 [英] mysql date and datetime problem

查看:55
本文介绍了mysql日期和日期时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 table1 的 mysql 表.带有 id 和 dt 列.dt 是日期时间类型.

I have a mysql table called table1. with id and dt columns. The dt is of type datetime.

由此,我试图提取具有特定日期的所有 ID(未给出时间,仅给出日期,例如 2011-02-11)

From this, I am trying to extract all id's with a specific date (not given the time, just the date, like 2011-02-11 say)

我可以在那个日期的 00:00:00 和午夜之间执行此操作,但它们是否是使用 mysql 和 php 执行此操作的正确方法?

I could do it as a between the 00:00:00 and midnight of that date, but is their a proper way to do it with mysql and php?

推荐答案

SELECT id, dt 
FROM table1
WHERE DATE(dt) = '2011-02-11'

MySQL 有一套非常全面的日期/时间处理函数,记录在 这里

MySQL's got a pretty comprehensive set of Date/Time handling functions, documented here

这篇关于mysql日期和日期时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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