You are not logged in.
Hello,
I'am trying to create a date parameter with formula, but it's not working as expected :
example #1:
${today == today.addYears(0).setMonth(12).setDay(11) ? today.addDays(-1) : today.addDays(1)}
which means :
if today_date = 11/12/2018
then 10/12/2018
else 12/12/2018
As current day is 11/12/2018, I am expecting to get the result 2018-12-10
but when executing, the returned value is 2018-12-12
I would like to try with :
${today == 2018-12-11 ? today.addDays(-1) : today.addDays(1)}
but I get an error "Cannot coerce '20181211' of class net.datenwerke.rs.utils.juel.wrapper.TodayWrapper to class java.lang.Long (incompatible type)"
example #2:
${today >= today.addYears(0).setMonth(12).setDay(15) ? today.firstDay() : today.lastDay()}
if today_date => 15/12/2018
then 01/12/2018
else 31/12/2018
I get the error : "lexical error at position 8, encountered invalid character '=', expected expression token"
operators like "=>" or ">=" or "ge" are not usable with dates ?
("ge" returns : Cannot compare 'class net.datenwerke.rs.utils.juel.wrapper.TodayWrapper' and 'class net.datenwerke.rs.utils.juel.wrapper.TodayWrapper')
As a newbie, I probably don't use the correct syntax, but I did not found examples on the forum or on other websites.
Offline
Hi FLU73,
please try with:
${today.equals(today.addYears(0).setMonth(12).setDay(11)) ? today.addDays(-1) : today.addDays(1)}
since today objects are dates, thus java objects, you cannot compare them with "==". Check here for more information:
https://www.admfactory.com/how-to-compa … s-in-java/
Regards,
Eduardo
Offline
Hi Eduardo,
Thanks for the link, but it seems to not work.
I've used the code : ${(today).compareTo(today.addYears(0).setMonth(04).setDay(01)) == 0 ? today.addYears(-1).addMonths(0).addDays(0) : today.addYears(1).addMonths(0).addDays(0)}
but when executing the query, I get the error : Method not found: class net.datenwerke.rs.utils.juel.wrapper.TodayWrapper.compareTo(net.datenwerke.rs.utils.juel.wrapper.TodayWrapper)
I wonder if date.compareTo() is found in the library, in the link they have :
package com.admfactory.date;
import java.text.SimpleDateFormat;
import java.util.Date;
Maybe something need to be added somewhere.
Offline
Hi FLU73,
please try with ${today.getDate().compareTo(today.addYears(0).setMonth(4).setDay(01)) == 0 ? today.addYears(-1).addMonths(0).addDays(0) : today.addYears(1).addMonths(0).addDays(0)}
Regards,
Eduardo
Offline
Hi Eduardo,
Ok, it's fixed.
I tried what you suggested:
${today.getDate().compareTo(today.addYears(0).setMonth(4).setDay(01)) == 0 ? today.addYears(-1).addMonths(0).addDays(0) : today.addYears(1).addMonths(0).addDays(0)}
Due to persistence of error message, I've replaced it by:
${today.getDate().compareTo(today.addYears(0).setMonth(4).setDay(01).getDate()) == 0 ? today.addYears(-1).addMonths(0).addDays(0) : today.addYears(1).addMonths(0).addDays(0)}
it works fine with == operator, but not with <, or <=
Finally, it works with: lt, gt
${today.getDate().compareTo(today.addYears(0).setMonth(4).setDay(01).getDate()) lt 0 ? today.addYears(-1).addMonths(0).addDays(0) : today.addYears(1).addMonths(0).addDays(0)}
or with: before, after
${today.getDate().before(today.addYears(0).setMonth(4).setDay(01).getDate()) ? today.addYears(-1).addMonths(0).addDays(0) : today.addYears(1).addMonths(0).addDays(0)}
Offline