Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
3154 มุมมอง

Hi: I want to find the difference between two dates ("project.task" model fields like "repeat_until" and "date_deadline", because subtracting the two dates doesn't work and using .days doesn't work.

Somebody help me. This is when we add a field in a model and I add validations to it.


Thanks

อวตาร
ละทิ้ง

Is "repeat_unit" date field?

ผู้เขียน

if it is a date field of a Projects model

คำตอบที่ดีที่สุด

explanation with an example

from datetime import datetime
fmt = '%Y-%m-%d'
from_date = '2013-09-01'     -> Take your date field1
to_date = '2013-09-31'       -> Take your date field2
d1 = datetime.strptime(from_date, fmt)
d2 = datetime.strptime(to_date, fmt)
daysDiff = str((d2-d1).days)          -> will gives you 29 days
daysDiff = str((d2-d1).days + 1)      -> will gives you 30 days

Hope it helps you ........ Thanks

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello,

        Can you be more specific..? Doesn't work in the sense? Please post your fields defined in your model and your code which doesn't work.

อวตาร
ละทิ้ง

Hi,

Have you solved this issue?

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ย. 23
1652
2
ม.ค. 24
14699
0
มิ.ย. 23
1122
9
พ.ค. 18
104743
0
พ.ย. 16
2851