gmo61520

Untitled

Feb 16th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. # simple version
  2. DAYS_PER_MONTH = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
  3. def ConvertDateToDaysSince2016(date):
  4. splitted = date.split('/')
  5. return sum(DAYS_PER_MONTH[1:int(splitted[0])]) + int(splitted[1])
  6.  
  7. # proper datetime version
  8. import datetime
  9. def ConvertDateToDaysSince2016_UsingDatetime(date):
  10. splitted = date.split('/')
  11. return (
  12. datetime.date(2016, int(splitted[0]), int(splitted[1])) - datetime.date(2016, 1, 1)
  13. ).days
  14.  
  15. print(str(ConvertDateToDaysSince2016_UsingDatetime('12/09')))
  16. print(str(ConvertDateToDaysSince2016('12/09')))
Advertisement
Add Comment
Please, Sign In to add comment