Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #
  2. #
  3. #
  4. #
  5. ########################################################
  6. """
  7. Geschrieben von D. Siefert am 02/05/2016
  8. Funktion ermittelt den letzten Tag eines Monats
  9. """
  10. ########################################################
  11. #
  12. #
  13. #
  14. #
  15.  
  16. from time import gmtime, strftime
  17. import datetime
  18.  
  19. #####def START#####
  20. def get_last_day_of_the_month():
  21. """
  22. Returns an integer representing the last day of the month, given
  23. a year and a month.
  24. """
  25.  
  26. # Algorithm: Take the first day of the next month, then count back
  27. # ward one day, that will be the last day of a given month. The
  28. # advantage of this algorithm is we don't have to determine the
  29. # leap year.
  30.  
  31. y = int(strftime("%Y"))
  32. m = int(strftime("%m"))
  33.  
  34. m += 1
  35. if m == 13:
  36. m = 1
  37. y += 1
  38.  
  39. first_of_next_month = datetime.date(y, m, 1)
  40. last_of_this_month = first_of_next_month + datetime.timedelta(-1)
  41. return last_of_this_month.day
  42. #####def ENDE#####
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement