By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

How to calculate the no. of days between two dates

P: 1
I have two dates in an interface.One is the warranty start date and the other one warranty end date.In the next field I have warranty period which should be generated automatically by calculating the number of days between warranty start date and the warranty end date.How is this possible?
Mar 24 '14 #1
Share this Question
Share on Google+
3 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
In Python, dates can be manipulated and date math can be performed with the time and datetime modules.
Mar 24 '14 #2

P: 7
Expand|Select|Wrap|Line Numbers
  1. from datetime import date
  2.  
  3. d0 = date(2008, 8, 18)
  4. d1 = date(2008, 9, 26)
  5. delta = d0 - d1
  6. print delta.days
  7.  
May 2 '14 #3

P: 2
Mild improvement ...
Expand|Select|Wrap|Line Numbers
  1. from datetime import date
  2.  
  3. d0 = date(2008, 8, 18)
  4. d1 = date(2008, 9, 26)
  5. delta = abs(d0 - d1)
  6. print(delta.days)
  7.  
May 18 '14 #4

Post your reply

Sign in to post your reply or Sign up for a free account.