作者:宋十七 | 来源:互联网 | 2023-10-12 20:14
IwanttoselectallrecordsfromatableLogwheretheDateAndTimefieldvalues(oftypedatetime)
I want to select all records from a table Log
where the DateAndTime
field values (of type datetime
) are for the day before today, whatever day it is.
我想从一个表日志中选择所有的记录,其中DateAndTime字段值(类型为datetime)用于前天,无论它是哪一天。
So if today is 2011-06-08, I want to select all rows where DateAndTime
is greater than or equal to 2011-06-07 00:00:00
and also less than 2011-06-08 00:00:00
.
如果今天是2011-06-08,我想选择日期和时间大于或等于2011-06-07 00:00并且小于2011-06-08 00:00的所有行。
I'm guessing the potential pitfall here would be it's behaviour on the 1st day of the month, as obviously a date like 2011-06-00
is invalid, and should be 2011-05-31
.
我猜这里潜在的陷阱可能是在一个月的第一天,因为像2011-06-00这样的日期显然是无效的,应该是2011-05-31。
5 个解决方案