[英]Django - count date between
我的數據庫中有很多記錄,其中包含日期時間字段(例如 2010-05-23 17:45:57)。
我想計算例如 15:00 和 15:59 之間的所有記錄(這一切都可以從其他日期、月份或年份開始)。 我怎樣才能做到這一點?
您可以將日期時間字段轉換為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 counter
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.