콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
3280 화면

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?

관련 게시물 답글 화면 활동
1
11월 23
1814
2
1월 24
14798
0
6월 23
1237
9
5월 18
104982
0
11월 16
2976