我是一个Python新手,正努力将经过的时间累积到一个变量中。数据来自时间和出勤计划。我要找的是在给定的开始日期/时间和每个记录中的结束日期/时间段内工作的总时间。我的代码如下:import pyodbc
import datetime
import time
fname = "\\\\frontoffice\z\data.mdb"
sname = "\\\\frontoffice\z\secured.mdw"
connect_string = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + fname +";UID=me;PWD=password;systemDB=" + sname + ";"
cnxn = pyodbc.connect(connect_string)
cursor = cnxn.cursor()
SQL = "SELECT EmpID, Weekending, Department, PayType, StartTime, EndTime FROM EmpHours WHERE EmpID=" + str(1) + " AND Weekending = #28/03/2015#;"
ttime = 0.0
for timerec in cursor.execute(SQL):
print timerec.Department, timerec.PayType,
if timerec.StartTime is not None:
print timerec.StartTime,
else:
print "",
if timerec.EndTime is not None:
print timerec.EndTime,
else:
print "",
if timerec.StartTime is not None and timerec.EndTime is not None:
print timerec.EndTime - timerec.StartTime
#ttime = ttime + timerec.EndTime - timerec.StartTime
print ttime
else:
print "n/a"
我的输出是:
^{pr2}$
我似乎无法改变timerec.StartTime/EndTime时间我也不能将时间初始化为空日期时间。日期时间变量。有什么想法吗?在