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

In one of my interface,I have two dates.One is the start date and other one is the end date.In the next field I want the total no.of days/month between these two dates to be automatically generated.There is no other specification regarding the dates or the total no.of days between the two dates.How to get the total number of days between the two given dates?

아바타
취소
베스트 답변

Hi Sneha,

Try this,

from datetime import datetime
date_format = "%m/%d/%Y"
a = datetime.strptime('8/18/2008', date_format)
b = datetime.strptime('9/26/2008', date_format)
delta = b - a
print delta.days # that's it

See following link

Hope it works for you

아바타
취소
작성자

Where to give this code?What if the date is not specified as 8/18/2008 and 9/26/2008

suppose your date format is '2014-12-31', for that your date_format will be '%Y-%m-%d'

작성자

This is to be added in the .py file right?

작성자

Which names are to be given instead of 8/18/2008 and 9/26/2008 in my code?

관련 게시물 답글 화면 활동
Project- Odoo 14 해결 완료
1
4월 21
4480
1
3월 15
11490
3
10월 24
7636
0
4월 22
3432
5
2월 20
5241