Notification emails - Calculate Difference Between Days?

Alexandros 10 months ago in Home Portal / Classic Projects updated by Thijs Senten 10 months ago 10

Hello everyone,

I wanted to try an idea where we would "remind" customers about upcoming payments before the invoice is overdue.

We would do this by using an #if in the reminder email to check if the current date is X days before the expected payment date and we would then use a different text, something like "Please remember that your invoice is due on XXX".

However, I am having trouble subtracting dates in XTRF (in fact, I am having trouble getting Dates and not strings to work with).

I would assume it would be done with something like:

#set($number_of_days_before_due=$utils.sub([GET_EXPECTED_PAYMENT_DATE, $now))

But I cannot find how to get the expected payment date. I would have assumed it was $customerInvoice.getExpectedPaymentDate() or

$customerInvoice.calculatePaymentDueDate() but that does not work. 

Does anyone have any ideas or pointers?

You can get to the payment date. But if you look at the class of customerInvoice, you see that it is a DynaBeanImpl object.


"class com.radzisz.xtrf.presentation.bean.DynaBeanImpl"

In order to get to all the properties of the customerInvoice, you should first 'Unwrap' it. So this should work:


Hello Denis, thank you for this. I had already come to that point, with the following problems:
1) This gives me the date in US format for some reason (e.g. 2019-9-16). 

2) I can still not get the current date in a proper date format

3) I have no idea how to compare or subtract the dates (it will not work on strings)

What I have so far is:



But this returns dates in different formats. The first as 16-09-2019 and the second as 2019-11-15.

I need to convert them and I think I also need to cast the strings to Dates.

First of all, the due date is in fact a Date object and not a string object. The representation is a string, but if you execute this: $due.class, you will get a java.time.LocalDate.
The $currentDate.date indeed gives you a java.lang.String. But the $utils.getCurrentDate() will give you a java.util.Date.

After that, you can search for some Java examples. I have created this. Not my best creation, but it does it's job.

#set($due = $utils.unwrap($customerInvoice).calculatePaymentDueDate())
#set($today = $utils.getCurrentDate())
#set($epochToday = $utils.roundDown($utils.div($today.getTime(),86400000)))
#set($epochDue = $due.toEpochDay())
#set($diff = $utils.sub($epochDue, $epochToday))

Thank you, that is amazing! It was exactly what I was trying to do. 

Is there any documentation for any of that somewhere? I am especially interested in any $utils documentation.

You should ask your account manager at XTRF for the JavaDoc. 
The $utils documentation is under VelocityTagUtils.

Hello! I found this topic very interesting. I wanted to ask if you know if there is a way to only include some clients? Or does it have to apply to all customer?

Thanks in advance for your reply.


I think you could probably assign a category to those clients you want to include, and then filter on that category using 'if'.

Category could do the trick indeed, or a custom field.

Yes, custom fields would work just as well, but you can have only 10 of each type, so on our side we try to save those for the special occassions ;-)

Hello Monika, 

You can do that in many different ways. One would be a custom Invoices view where you only select the customers you want to send reminders to. The other would be to add bad payers in a new category either manually or using a Macro (which could e.g. check the number of days each customer has delayed payments over the last year and then change the category for customers if that exceeds an acceptable number).