我有一个数据库表,其中有一列OccurDate
datatype DateTime
。
数据是这样的...
06-03-2013 06:47:49
06-03-2013 16:47:49
我必须找到 InTime、OutTime、WorkDuration。
我正在使用这样的查询
Min(convert(varchar(10),OccurDateTime,108)) AS InTime,
Max(convert(varchar(10),OccurDateTime,108)) AS OutTime,
但我在计算时遇到workDuration
了问题,因为
workDuration = 16:30:00 - InTime //16:30:00 means 4:30 pm
而银泰现在是varchar(10)
这样,它不能减去Datetime
......
我正在使用的查询..
SELECT UserID AS EmpCode,FirstName,LastName,Department,convert(varchar(10),OccurDateTime,103) AS Date,Min(convert(varchar(10),OccurDateTime,108)) AS InTime,
Max(convert(DateTime,OccurDateTime,108)) AS OutTime,
convert(varchar(10),(Max(convert(DateTime,OccurDateTime,108))- Min(convert(DateTime,OccurDateTime,108))),108) as Work,
FROM TTransactionLog1
WHERE convert(varchar(10),OccurDateTime,103) = '14/03/2013'
GROUP BY UserID, FirstName, convert(varchar(10),OccurDateTime,103),LastName,Department
所以你们有什么想法......