How to get the Compare Date Value with Current Date

Confluence User - 10 Aug, 2022

Hello all, I’m trying to get the Compare Date Value with Current Date function/script to work, but can’t seem to figure it out.


here is the page and Script Joget provides from here: Compare Date Column Value with Current Date


import java.text.ParseException;
import java.time.LocalDate;
import java.time.Period;
 
try {
    LocalDate birthDate = LocalDate.parse(value);
    LocalDate currentDate = LocalDate.now();
     
    Period dateDiff = Period.between(birthDate, currentDate);
     
    return dateDiff.getYears() + " YEAR(s) & " + dateDiff.getMonths() + " MONTH(s)";
} catch (ParseException e) {
    e.printStackTrace();
}



I don’t quiet understand what all I need to change in the script to get it working.  I’m trying to track how long it’s been since routine maintenance has been done on buildings I manage.


thanks for the help!!

javascript;datalists

4


11 Aug, 2022
confluenceUser
confluenceUser

Hi, it depends on where you wish to perform the date calculation. That script above is a BeanShell script used as a datalist formatter. If you want to calculate using custom JavaScript then there is an example at Calculate Date Range.

11 Aug, 2022
confluenceUser
confluenceUser

Hi Anders, I misspoke.  I’d like to use the BeanShell script in the BeanShell Formatter in the data list columns.

Ultimately, I want to select 1 date an action was performed, and the system to tell me how many days it’s been since that action was performed based on the date.

From my understanding, it should do that with the above BeanShell script.  This would only force the user to update one thing, and then the system would show how many days has elapsed since that action took place.

Eventually after that, I’d like to get the CRON Scheduler to the automatically send emails when those dates have reached 45 days, 60 days, and then 90 days.  But I will cross that bridge when I get to it.

Im just focused now on getting the BeanShell script in the Datalist formatter to work.


thank you for the help!

11 Aug, 2022
confluenceUser
confluenceUser

Hi Anders, I misspoke.  I’d like to use the BeanShell script in the BeanShell Formatter in the data list columns.

Ultimately, I want to select 1 date an action was performed, and the system to tell me how many days it’s been since that action was performed based on the date.

From my understanding, it should do that with the above BeanShell script.  This would only force the user to update one thing, and then the system would show how many days has elapsed since that action took place.

Eventually after that, I’d like to get the CRON Scheduler to the automatically send emails when those dates have reached 45 days, 60 days, and then 90 days.  But I will cross that bridge when I get to it.

Im just focused now on getting the BeanShell script in the Datalist formatter to work.


thank you for the help!

18 Aug, 2022
confluenceUser
confluenceUser

What errors are you getting in the logs? I saw Ian's comment above saying that the script is working, there might be something different in your environment that should show up in the logs.

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print