Forum Discussion

senthkum's avatar
senthkum
Contributor
5 years ago

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/msgGetTransactionListRequest/SearchCriteria/DateRange/FromDate")
def ToDate = holder.getNodeValue("declare namespace ns='http://mebank.com.au/Enterprise/AccountManagement/wsdl/AccountService/1.0';//ns:getTransactionList/msgGetTransactionListRequest/SearchCriteria/DateRange/ToDate")

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

7 Replies

    • senthkum's avatar
      senthkum
      Contributor

      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

      • nmrao's avatar
        nmrao
        Champion Level 3
        What are you expecting in result? Sample data please?