cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing a date in groovy.

SOLVED
Highlighted
Community Hero

Re: Date Parse SOAP UI Issue?

You aren't paying attention to the solutions provided where there are clear proven solutions. And not even comments by Rupert.

If you have even tried copy and paste, you would have realized the error that is being made.

Any ways, you using YYYY instead of yyyy. And use below

def newDate= Date.parse("yyyy-MM-dd'T'HH:mm:ss", '1971-12-28T00:00:00').format('MM/dd/yyyy')
log.info newDate



Regards,
Rao.
Highlighted
New Contributor

Re: Date Parse SOAP UI Issue?

Hi @ilovechiku 


@ilovechiku wrote:

Not sure why the behavior is so strange in Parsing..

 

I have code like this

//capturing date from response before date parse

def bday =jsonResponse.Demographics.BirthDate

 

log.info "Response date Before Date Parse "+bday

//Parsing the date from response above

def newDate= Date.parse("yyyy-MM-dd'T'HH:mm:ss", bday).format('MM/dd/YYYY')

 

log.info "Response Date"+newDate

 

Output :

Response date Before Date Parse 1971-12-28T00:00:00
Response Date12/28/1972 ---??? WHY IS THIS DATE ADDING A EXTRA year?

 

 


You are getting the above output because you are using the wrong date format. MM/dd/yyyy is right way to use. Replace last line with below

def newDate= Date.parse("yyyy-MM-dd'T'HH:mm:ss", bday).format('MM/dd/yyyy')



New Here?
Join us and watch the welcome video:
Read the Latest News
JuneSCNJ
Top Kudoed Authors