To move the date in python the following code may help.
Using this function we can move the days in both past date and future date by specifying the no of movedays with -ve/+ve sign accordingly.
</pre> import datetime def move_days(year,month,day,movedays): ''' move_days : To move the day both direction and get the moved date yyyymmdd format Condition : passing year,month,day,movedays should be integer type. Inputs: movedays is an integer to move the date. It it is negative, then we should get the previous date with interval of the no of days [i.e. movedays ] Outputs: It should return the string type of the date formate like yyyymmdd Usage: example: move_days(2011,04,03,200) returns '20111020' move_days(2011,04,03,-200) returns '20100915' Written by: Arulalan.T Date: 03.04.2011 ''' if not (isinstance(year,int) and isinstance(month,int) and isinstance(day,int) and isinstance(movedays,int) ): raise ValueError, ' year, month, day, movedays should be integer type ' daychanges = datetime.date(year,month,day) + datetime.timedelta(days = movedays) daychanges = daychanges.timetuple() year = str(daychanges) month = str(daychanges) if len(month) == 1 : month = '0' + month day = str(daychanges) if len(day) == 1 : day = '0' + day return year + month + day
🙂 What I am learning here is, how to do coding and documentation in well good manner by myself 🙂Advertisements