How to convert StringPath to DatePath with custom function and selected value?
I want use value from database in custom predicate like below
public static Predicate hasBirthdateGreaterOrEqual(String from) {
//how to convert this to String and pass to PeselParser(String value)
StringPath peselValue = QEmployee.employee.employment.person.peselValue;
LocalDate employeeDate = new PeselParser(peselValue).getDate();
DateExpression<LocalDate> expression = DateTemplate.create(LocalDate.class, from);
return expression.goe(employeeDate);
}
Use DateTemplate's create(Class<T> type, String template, Object one) method. Dependant upon your RDBMS, you're going to want to alter the following template String. I've gone with Oracle for the example:
DateTemplate.create(LocalDate.class, "TO_DATE({0}, 'DD/MON/YYYY')", from);
I see you're using the version 3 syntax. Querydsl 4 has been out for a while now. I'd consider upgrading. We've done it for a large reporting project and it actually wasn't too painful. In querydsl 4, I believe you would use Expressions.dateTemplate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With