Forum Discussion

dinojadhav's avatar
dinojadhav
Occasional Contributor
6 years ago
Solved

Help with Date conversion as per the required format - groovy

Hello All,

I have to validate the new date coming in my xml response. Tried below groovy script but facing problem in comparing dates as the dates are in String format.

Basically I am trying to validate my new journey date, say my previous journey date is 21 Oct. 19 and now i change the same to 23 Oct. 19, now i have to validate the 23 Oct. 19.

 

As i am new to programming unable to crack it, tried below :

def odate = messageExchange.modelItem.testStep.testCase.testSuite.getPropertyValue ("DepartureDateTime")
log.info odate

def dateFormat = new SimpleDateFormat("dd-MM-yyyy")
def dateString = ndate
log.info dateString
def changedDate = dateFormat.parse("dateString")
log.info changedDate

odate = new Date().parse('yyyy/MM/dd')
log.info odate

def dateDifference = messageExchange.modelItem.testStep.testCase.testSuite.getPropertyValue ("datediff") as int
log.info dateDifference
assert odate == ndate - dateDifference