get first day and last day of month on given user input date

Viewed 402

user input for start time and end time.

Dates input format, "%Y-%m-%dT%H:%M:%S

st = 2018-10-10T00:00:00
et = 2018-03-30T23:59:59

after conversion it should look like:-

st1 = 2018-10-01T00:00:00 --> first day of month
et1 =  2018-06-31T23:59:59 ---> last day of month
1 Answers

I find arrow module most efficient for this kind of purpose.

import arrow

st = "2018-10-10T00:00:00"
et = "2018-03-30T23:59:59"


first_day = arrow.get(st).floor('month')
last_day = arrow.get(et).ceil('month')

print(first_day)
print(last_day)

# output

2018-10-01T00:00:00+00:00
2018-03-31T23:59:59.999999+00:00
Related