Where did this come from? None of those are good expressions because they do not force the date to be in a certain format before doing the string manipulation. So, depending on the regional settings, they could produce entirely different results.
However, A does look to be the intended correct answer. I'll try to explain what I see. There are a couple of problems with trying out the expression. First, if your regional settings for date formats are different then it'll either error or give you a wrong result. Second, there are semicolons, so I don't know what's going on there. But, if you assume the semicolons would work or change them to commas, then the rest of it makes sense depending on regional settings.
A:
- Mid(Today(); 4; 2) is intended to get the month, and Mid(Today(); 7; 4) is intended to get the year, both as numbers. It also appears to be expecting a date format of dd/MM/yyyy.
- If I resolve the two mid functions (assuming today is Feb 3rd, 2021) then the remaining expression looks like this:
- AddDays(AddMonths(MakeDate(01; 2;2021);1), -1)
- MakeDate(01; 2;2021) resolves to be a date of Feb 1st, 2021 (the goal was to get the first day of the current month.
- Then AddMonths will add one month to the date so that we get March 1st, 2021.
- Then AddDays (with -1) subtracts a day from that date so we get Feb 28th, 2021.
So, with that in mind, here's my expression to get the same thing, but 'should' work regardless of regional settings:
- MakeDate(1, ToNumber(FormatDate(AddMonths(Today(),1),"MM")), ToNumber(FormatDate(AddMonths(Today(),1),"yyyy")))-MakeTimeSpan(1,0,0,0)
It could be less wordy with multiple expressions, but I wanted it in a single expression
Dave Morris, 3Ci at Southern Company