首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Django -计数日期介于

问Django -计数日期介于
EN

Stack Overflow用户
提问于 2010-05-31 19:22:44
回答 1查看 295关注 0票数 0

我的数据库中有很多包含日期时间字段的记录(例如2010-05-23 17:45:57)。

我想要计算15:00到15:59之间的所有记录(可以是其他日期、月份或年份)。我该怎么做呢?

EN

回答 1

Stack Overflow用户

发布于 2010-06-01 23:52:28

您可以将日期时间字段转换为Julian Dates,然后进行直接比较:

代码语言:javascript
复制
# 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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2943174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档