How to calculate the no. of days between two dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sneha3
    New Member
    • Mar 2014
    • 1

    How to calculate the no. of days between two dates

    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?
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    In Python, dates can be manipulated and date math can be performed with the time and datetime modules.

    Comment

    • maya29988
      New Member
      • May 2014
      • 7

      #3
      Code:
      from datetime import date
      
      d0 = date(2008, 8, 18)
      d1 = date(2008, 9, 26)
      delta = d0 - d1
      print delta.days

      Comment

      • vegaseat
        New Member
        • May 2014
        • 2

        #4
        Mild improvement ...
        Code:
        from datetime import date
        
        d0 = date(2008, 8, 18)
        d1 = date(2008, 9, 26)
        delta = abs(d0 - d1)
        print(delta.days)

        Comment

        Working...