Kibby

Python Date

Apr 6th, 2021
412
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def time_delta(first_date, second_date):
  2.     first_date = first_date.split('.')
  3.     second_date = second_date.split('.')
  4.  
  5.     monthDays = [31, 28, 31, 30, 31, 30,
  6.              31, 31, 30, 31, 30, 31]
  7.  
  8.     def countLeapYears(d):
  9.  
  10.         years = int(d[2])
  11.    
  12.         if (int(d[1]) <= 2):
  13.             years -= 1
  14.  
  15.         return int(years / 4) - int(years / 100) + int(years / 400)
  16.  
  17.     def getDifference(dt1, dt2):
  18.  
  19.         n1 = int(dt1[2]) * 365 + int(dt1[0])
  20.  
  21.         for i in range(0, int(dt1[1]) - 1):
  22.             n1 += monthDays[i]
  23.    
  24.         n1 += countLeapYears(dt1)
  25.    
  26.         n2 = int(dt2[2]) * 365 + int(dt2[0])
  27.         for i in range(0, int(dt2[1]) - 1):
  28.             n2 += monthDays[i]
  29.         n2 += countLeapYears(dt2)
  30.  
  31.         return abs(n2 - n1)
  32.    
  33.     print(getDifference(first_date, second_date))
  34.    
  35. time_delta('10.4.2021', '7.4.2021')
  36.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×