我的数据库中有很多包含日期时间字段的记录(例如2010-05-23 17:45:57)。
我想要计算15:00到15:59之间的所有记录(可以是其他日期、月份或年份)。我该怎么做呢?
发布于 2010-06-01 23:52:28
您可以将日期时间字段转换为Julian Dates,然后进行直接比较:
# 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 counterhttps://stackoverflow.com/questions/2943174
复制相似问题