跳至内容
菜单
此问题已终结
1 回复
11323 查看

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?

相关帖文 回复 查看 活动
1
4月 21
4416
1
3月 15
11381
3
10月 24
7463
0
4月 22
3341
5
2月 20
5161