Forums

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

Compare custom field dates in behaviour ?

zhangqian04
Contributor
December 19, 2019 edited

I am desperately trying to compare 2 dates from custom fields in the issue screen, but nothing happens and I can't find the problem in my code:

-------------------------------------------------------------------------
def StartDateField = getFieldByName("Start date")


def EndDateField = getFieldByName("End date")

 


Date StartDateValue = (StartDateField.value as Date)
Date EndDateValue = (EndDateField.value as Date)


if ( StartDateValue.getTime() > EndDateValue.getTime() ) {

 EndDateField.setError("EndDateValue cannot be earlier than StartDateValue")
} else {

EndDateField.clearError()
}

-----------------------------------------------------------------------

Your help will be much appreciated!

1 answer

0 votes
Alok Singh December 19, 2019

Convert the both date in yyyymmddmmss and compare it.

covert like 201912191530 and 201912180930 and compare.

zhangqian04
Contributor
December 19, 2019 edited

how to convert ?  after convert , Is it compared as a string?

thanks

Suggest an answer

Log in or Sign up to answer