python 时间差 怎么存,如何在Python中将时间差累积到变量中

我是一个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时间我也不能将时间初始化为空日期时间。日期时间变量。有什么想法吗?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值