我的CheckTime
输出格式为8/17/2014 5:45:22 PM
。我如何比较CheckTime
和Date()
?
SELECT c.Userid, c.CheckTime, 'Sign In' AS Action
FROM Checkinout c
WHERE c.CheckType = 'I' AND Format(CheckTime, "mm/dd/yyyy") = Date()
UNION
SELECT c.Userid, c.CheckTime, 'Sign Out' AS Action
FROM Checkinout c
WHERE c.CheckType = 'O' AND c.CheckTime = Date();
答案 0 :(得分:0)
我假设你也想记录结账吗?您打算如何将签到与相应的结账相匹配?
为什么不改变这样的表格呢?
| UserId | CheckInTime | CheckOutTime |
然后你可以这样做:
SELECT c.Userid, c.CheckInTime, c.CheckOutTime,
IIF ( NOT ISNULL(c.CheckOutTime),
DateDiff("n",c.CheckTime,c.CheckTime)/60 & "." &
DateDiff("n",c.CheckTime,c.CheckTime) Mod 60,
NULL) as TimeElapsed,
FROM Checkinout c;
注意:这会花费几小时和几分钟,但你可以做类似的事情来获取日期和时间。