[python] finding first day of the month in python

The arrow module will steer you around and away from subtle mistakes, and it's easier to use that older products.

import arrow

def cleanWay(oneDate):
    if currentDate.date().day > 25:
        return currentDate.replace(months=+1,day=1)
    else:
        return currentDate.replace(day=1)


currentDate = arrow.get('25-Feb-2017', 'DD-MMM-YYYY')
print (currentDate.format('DD-MMM-YYYY'), cleanWay(currentDate).format('DD-MMM-YYYY'))

currentDate = arrow.get('28-Feb-2017', 'DD-MMM-YYYY')
print (currentDate.format('DD-MMM-YYYY'), cleanWay(currentDate).format('DD-MMM-YYYY'))

In this case there is no need for you to consider the varying lengths of months, for instance. Here's the output from this script.

25-Feb-2017 01-Feb-2017
28-Feb-2017 01-Mar-2017