Get previous month from 202401

I have a parameter that is in the format yyyydd, e.g. 202401 and I need to create another parameter for the previous month, which in this case would be 202312, but I can't for the life of me get anything to work.

I can get the addmonths function to work if I use a specific date, but I can't work out how to parse a date into addmonths for it to work - if I have a parameter e.g. {FullMonth} which is 2024-01-01, if I do addmonths({FullMonth},-1) i get

ERROR:Inappropriate argument for AddMonths(date_as_number, number)

I'm trying to work back from this:

format(addmonths(#2024-01-01,-1),'yyyyMM')

Which gives me the required output - please help!

The addmonths() function, as all the date/time functions in EasyMorph, expects a number date, because in EasyMorph dates are numbers. You need to convert your text date into a number date first. Then use addmonths() and convert back to a text date.

LET month_year = date({YearMonth}, 'yyyyMM')
format(addmonths(month_year,-1),'yyyyMM')
1 Like

Wow - wasn't expecting a response so quick on a Sunday!

I just happened to be around my computer :slight_smile:

1 Like