Question
How to use or/|| in an expression
Hi,
I want to write an expression to find the last day of the month. To find the last day of the month i have written the following expression;
If(equals(@String.toInt(String.substring(@DateTime.getCurrentDateStamp(),4,6)),01||03||05||07||08||10||12), "2017" + @String.substring(@DateTime.getCurrentDateStamp(),4,6) + "31", "010101")
This is the error that i''m getting;
Invalid expression or reference: line 1:74 mismatched input ',' expecting {')', '-', '+', '=', '*', '/', '%', '<', '>', '<=', '>=', '==', '!=', '<>', '^=', '~=', '&&', '||', '?', '+=', '-=', '*=', '/=', '%='}
@If(@equals(@String.toInt(String.substring(@DateTime.getCurrentDateStamp(),4,6)),01||03||05||07||08||10||12)),"2017"+@String.substring(@DateTime.getCurrentDateStamp(),4,6)+"31","010101")
^
The ||/or doesn't seem to work, can anyone help me figure out what i'm doing wrong here?
I would recommend finding the first day of next month, and subtracting one day from that. (You don't want to rewrite logic for leap year) For maintainability, I'm splitting it up into Params assuming you're doing this in a property-set:
With all date-time manipulation like this, you have to be careful about timezones. Because pega uses GMT in many of these calculations, odd things might happen if you are ahead or behind GMT. getCurrentDateStamp might be good for testing, but I think you might want to use something that takes the user's time zone into account. I would test carefully around flipping over from one day to the next, one month to the next, and one year to the next.