Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
11370 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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'

Tác giả

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

Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
Project- Odoo 14 Đã xử lý
1
thg 4 21
4426
1
thg 3 15
11424
3
thg 10 24
7494
0
thg 4 22
3378
5
thg 2 20
5169