2010-05-31 4 views
0

입니다. 데이터베이스에 날짜/시간 필드가 많은 레코드가 있습니다 (예 : 2010-05-23 17:45:57).
예를 들어 모든 레코드를 계산하고 싶습니다. 15:00 및 15:59 (모두 다른 날, 달 또는 1 년). 어떻게해야합니까?장고 - 계산 날짜가

+1

http://stackoverflow.com/questions/917996/how-do-i-filter-by-time-을 in-a-date-time-field –

답변

0

당신은 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