我有一个日期收集在哪里
from to
2018-01-24 14:02:00 | 2018-01-29 16:02:00
2018-01-25 16:02:00 | 2018-01-29 16:02:00
2018-01-26 14:02:00 | 2018-01-29 16:02:00
2018-01-27 14:02:00 | 2018-01-30 16:02:00
编辑:我的参数只有1个值,即今天的日期时间
我想搜索日期时间在哪里
我怎样才能做到这一点?
表格:
tbl_announcements
列,从,到
最佳答案
首先,我真的建议您不要从中命名列,因为它是表选择的受保护标识符。
我不知道SQL是否可以让您为列命名,但是如果可以的话,我会尽快将其重命名。如果没有别的,它将使您的代码更具可读性。
通常,尝试避免在编码中使用与强类型词匹配的名称。最后,您会省下很多眼泪。
假设您的表格是:
表格SearchByDateTime
ID(PK)| FromDate |至今
那么您的查询将是(以伪代码形式):
declare @targetDate Datetime;
Set @targetDate = "2017-01-01 00:00:00"
Select * from SearchByDateTime sbdt
where sbdt.FromDate >= @targetDate and sbdt.ToDate <= @targetDate
如果您有两个目标值,也可以这样做:
declare @targetDateBegin Datetime;
declare @targetDateEnd Datetime;
Set @targetDateBegin = "2017-01-01 00:00:00"
Set @targetDateBegin = "2017-02-01 00:00:00"
where sbdt.FromDate >= @targetDateBegin and sbdt.ToDate <= @targetDateEnd
但是,您的问题不是很具体,如果您要澄清的话,我的回答可能会更加准确...
关于mysql - 搜索日期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48500476/