cancel
Showing results for 
Search instead for 
Did you mean: 

Help with Date conversion as per the required format - groovy

SOLVED
Highlighted
Occasional Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Occasional Contributor

Re: Help with Date conversion as per the required format - groovy

Hi Sonia,

 

I have found a solution.

 

Thanks for the concern.

 

Best Regards,

Dinesh

View solution in original post

4 REPLIES 4
Highlighted
Community Hero

Re: Help with Date conversion as per the required format - groovy

Please provide sample data with same json structure (need not be exact data) and what data you are comparing?


Regards,
Rao.
Highlighted
Community Manager

Re: Help with Date conversion as per the required format - groovy

Hi @dinojadhav! Have you found a solution? If not, please provide more details, and we will do our best to try and help you here.

 

 

 


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
Occasional Contributor

Re: Help with Date conversion as per the required format - groovy

Hi Sonia,

 

I have found a solution.

 

Thanks for the concern.

 

Best Regards,

Dinesh

View solution in original post

Highlighted
Community Manager

Re: Help with Date conversion as per the required format - groovy

HI @dinojadhav, I am very glad to hear this! Could you share your solution with the Community? We would really appreciate it. Thank you!


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Compete with community members in the TechCorner Challenge and get into the Leaderboard!

Rank Participant Points Earned
1 msiadak 12
2 nmrao 8
3 HimanshuTayal 3
Top Kudoed Authors