Skip to content

Instantly share code, notes, and snippets.

@romulojales
Created February 26, 2014 02:27
Show Gist options
  • Save romulojales/9222361 to your computer and use it in GitHub Desktop.
Save romulojales/9222361 to your computer and use it in GitHub Desktop.
Some functional methods with months
import calendar
from datetime import datetime
import pytz
def month_range(year, month):
init = datetime(year, month, 1, 0, 0, 0, 0, tzinfo=pytz.UTC)
max_day_month = calendar.monthrange(year, month)[1]
final = datetime(year, month, max_day_month, datetime.max.hour, datetime.max.minute,
datetime.max.second, datetime.max.microsecond, tzinfo=pytz.UTC)
return init, final
def get_previus_month(month, year):
month -= 1
if month <= 0:
month += 12
year -= 1
return month, year
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment