cancel
Showing results for 
Search instead for 
Did you mean: 

Need to find the datediff for the below code?

SOLVED
Contributor

Need to find the datediff for the below code?

Hi Team,

 

I have a requirement where I need to get the FromDate and ToDate form the incomming request and find the datediff to send the response. I have pasted the below code, could you guide me in finding the datediff ?

 

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
def FromDate = holder.getNodeValue("declare namespace ns='http://mebank.com.au/Enterprise/AccountManagement/wsdl/AccountService/1.0';//ns:getTransactionList/m...")
def ToDate = holder.getNodeValue("declare namespace ns='http://mebank.com.au/Enterprise/AccountManagement/wsdl/AccountService/1.0';//ns:getTransactionList/m...")

def Fromdate = new Date().parse("yyyy-MM-dd'T'HH:mm:ss.000+11:00", FromDate).format('yyyy-MM-dd')
def Todate = new Date().parse("yyyy-MM-dd'T'HH:mm:ss.000+11:00", ToDate).format('yyyy-MM-dd')

def intValue = Todate.minus(Fromdate) Is this the correct formate to find the datediff?
def Nofodays = intValue.toInteger()

 

Error: Failed to dispatch using script; java.lang.NumberFormatException: For input string: "2020-02-19"

 

Based on NoofDay I need to send the Resposne:

1. return Weekly,

2. return Fortnight,

3. return Month,

4. return Year,

 

Thanks

Senthil. M

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Need to find the datediff for the below code?

@senthkum 

Please see the script hosted at github

 

By the way you can try testing online here



Regards,
Rao.

View solution in original post

7 REPLIES 7
Highlighted
Community Hero

Re: Need to find the datediff for the below code?

Error says that String class does not have parse method.
You are omitting the time, is it expected that way?
Please refer thread to parse
https://stackoverflow.com/questions/3817862/groovy-string-to-date


Regards,
Rao.
Highlighted
Contributor

Re: Need to find the datediff for the below code?

Thanks Mate,

 

I was able to resolve the older problem. But now I have another problem. What could be the issue for the below error?

I am not able to convert string date to date format, even though I have paresd.

 

def Fromdate = new Date().parse("yyyy-MM-dd'T'HH:mm:ss.000+11:00", FromDate).format('yyyy-MM-dd')
def Todate = new Date().parse("yyyy-MM-dd'T'HH:mm:ss.000+11:00", ToDate).format('yyyy-MM-dd')

 

def intValue = Todate.minus(Fromdate) Is this the correct formate to find the datediff?
def Nofodays = intValue.toInteger()

Error: Failed to dispatch using script; java.lang.NumberFormatException: For input string: "2020-02-19"

 

Thanks

Senthil. M

Highlighted
Community Hero

Re: Need to find the datediff for the below code?

What are you expecting in result? Sample data please?


Regards,
Rao.
Highlighted
Contributor

Re: Need to find the datediff for the below code?

Hi Rao,

I want to find the date difference to send my response. Should I add any .jar files to work on date format ?

If so, Can you provide the link plz.

 

Though the FromDate and ToDate is parsed it's still showing as string, due to that I am not able to do a datediff.

I have spent 2 days on this to resolve. Could you help me here. 

 

def Fromdate = new Date().parse("yyyy-MM-dd'T'HH:mm:ss.000+11:00", FromDate).format('yyyy-MM-dd')
def Todate = new Date().parse("yyyy-MM-dd'T'HH:mm:ss.000+11:00", ToDate).format('yyyy-MM-dd')

def intValue = Todate - Fromdate
def Nofodays = intValue.toInteger()

 

if ((Nofodays >=8 ) || (Nofodays <= 15))
{
return "Fortnight"
}
else if ((Nofodays >=16 ) || (Nofodays <= 31))
{
return "Month"
}

 

Thanks

Senthil. M

Highlighted
Community Hero

Re: Need to find the datediff for the below code?

@senthkum 

Please see the script hosted at github

 

By the way you can try testing online here



Regards,
Rao.

View solution in original post

Highlighted
Contributor

Re: Need to find the datediff for the below code?

Hi Rao,

 

Thanks for the update, I tried with the code you gave a made small change as per my requirement. I now do not see any error. But not able to see the data in the application. Will debug with developer and track where the issue is. Will get back to you if I face ant issues.

Thanks a lot for your support.

 

Thanks

Senthil. M

Highlighted
Community Hero

Re: Need to find the datediff for the below code?

Glad it helped.
Would it be possible to close other threads as well which you created for date?


Regards,
Rao.