问题描述
日期存储在DB中,例如:"datetime"字段中的"2011-05-26 11:00:00".我想查找日期大于本月初的所有行,即:2011-05-01 09:00:00
Dates are stored in DB as such: "2011-05-26 11:00:00" in a datetime field. I'd like to find all rows where the date is greater than the first of this month, ie: 2011-05-01 09:00:00
不能更改数据库中的日期格式.我可以使用什么MySQL函数将数据库中的日期转换为可以比较的格式?我猜第一个月"的最佳格式是Unix时间戳吗?
The date formats in the DB can not be changed. What MySQL function can I use to convert the date in the DB to a format that can handle comparison? I'm guessing the best format for "first of the month" is a unix timestamp?
日期中的时间值始终存在,但只有办公时间,因此从09:00到17:00.
The time values in the dates are always present but only office hours, so from 09:00 to 17:00.
推荐答案
如果存储在DATETIME
字段中,只需在WHERE date > '2011-05-01 09:00:00'
上查询.
If it's stored in a DATETIME
field, just query on WHERE date > '2011-05-01 09:00:00'
.
这篇关于MySQL日期比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!