I’ve got a somewhat unique problem. I need to write a function that accepts a date, and adds a day to it. This gets difficult because of the # of days in a month. I’ve started writing a function that’s extremely messy and inefficient, so I was hoping I could get some input on the correct or best way to do this…
Example of what I’ve got started (psuedo-code):
function AlterDate(oldDate){
//if oldDate’s month = december, and day = 31, set month=1, day=1, increment year.
//elseif oldDate’s month has 30 days, and day=30, increment month and set day to 1
//elseif oldDate’s month is= feb, and day=28, increment month and set day =1.
//elseif oldDate’s month has 31 days, and day=31, increment month and set day to 1
//else increment day.
return newDate;
}
So for example, if 10/31/2009 is passed in, I need to return 11/01/2009.
jan 31 feb 28/29 mar 31 apr 30 may 31 jun 30
jul 31 aug 31 sep 30 oct 31 nov 30 dec 31
Thanks!