Python Django-计数日期介于
我的数据库中有许多包含日期时间字段的记录(例如2010-05-23 17:45:57)。Python Django-计数日期介于,python,django,Python,Django,我的数据库中有许多包含日期时间字段的记录(例如2010-05-23 17:45:57)。 我想计算15:00和15:59之间的所有记录(可以从其他日期、月份或年份开始计算)。如何执行此操作?您可以将日期时间字段转换为 然后做一个直接的比较: # Input is a list with the time of all the records, t_record_all # Loop over all the records counter = 0 jd_low = ... #(this is
我想计算15:00和15:59之间的所有记录(可以从其他日期、月份或年份开始计算)。如何执行此操作?您可以将日期时间字段转换为 然后做一个直接的比较:
# Input is a list with the time of all the records, t_record_all
# Loop over all the records
counter = 0
jd_low = ... #(this is your lower time limit in JD)
jd_hi = ... # (this is your higher time limit in JD)
for t_record in t_record_all:
# Convert the time to julian date format
jd_record = ... #(do your conversion here)
if (jd_low <= jd_record <= jd_hi):
# increment record counter
counter = counter + 1
print counter
#输入是一个包含所有记录时间的列表,t#u record#u all
#循环浏览所有记录
计数器=0
jd_低=#(这是您在JD中的较低时间限制)
jd_hi=…#(这是您在JD中的较高时间限制)
对于t_record_all中的t_record:
#将时间转换为朱利安日期格式
jd_记录=#(在此处进行转换)
如果(jd_低