-1

As every month have different days in it, so i can't apply timedelta=30.

I want to get three variables

month_start,

month_end ,

month_days = month_end - month_start

Which will be correspond to start date of month and end date of month. and their interval will be number of days in the month.

for instance , for march : month_days = 31, april : month_days = 30

ancho
  • 1,060
  • 16
  • 24

1 Answers1

3

Use calendar module to get days from months

>>> import datetime
>>> import calendar
>>> now = datetime.datetime.now()
>>> print calendar.monthrange(now.year, now.month)[1]
31

For 2015 Feb month

>>> calendar.monthrange(2015, 2)
(6, 28)

https://docs.python.org/2/library/calendar.html

Vivek Sable
  • 9,938
  • 3
  • 40
  • 56