Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scripted field calculate from two date fields

April Alletha Lopez September 7, 2018

Hi,

I need to create a scripted datetime field based on difference in duration between two datetime fields.

Formula:

DateTime3 = DateTime1 + (25% of duration from DateTime1 to DateTime2)

Legend:

DateTime1 => input Field, Date Time Picker
DateTime2 => Scripted Field based on DateTime1, Date Time Picker
DateTime3 => Scripted Field, Date Time Picker

This is not working:

def period = (DateTime2.getTime() - DateTime1.getTime()) * 0.25;
return new java.sql.Timestamp(DateTime1.getTime() + period);

Any suggestions?

Thanks.

1 answer

1 accepted

1 vote
Answer accepted
Elifcan Cakmak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 11, 2018

Hello

What error do you get?

Can you try converting period to integer like this:

return new java.sql.Timestamp(DateTime1.getTime() +period.toInteger());

When I try your code with this, it seems to work.

April Alletha Lopez September 11, 2018

Thanks! That helped :)

What I did:

def DateTime1 = getCustomFieldValue("<name>") as Date --> for all dates

def period = (DateTime2.getTime() - DateTime1.getTime()) * 0.25.toDouble();
return new java.sql.Timestamp(DateTime1.getTime() + period.toInteger());

Elifcan Cakmak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 11, 2018

Hi, you're welcome :)

Suggest an answer

Log in or Sign up to answer