Forum Discussion

go2khurram's avatar
go2khurram
Contributor
9 years ago

Need to insert tomorrow's date in JDBC Request Step in "yyyy-MM-dd'T'HH:mm:ss" format

Hi,

 

I need to insert a row having tomorrow's date as a value of date column by using the JDBC request step. Along with date I am reading some other values from by previous JDBC result. I have manage yo write a groovy script to format the date in required format by using below code

import groovy.time.TimeCategory
use ( TimeCategory )
{
	def tmpDate = new Date() + 2.days
	log.info tmpDate.format("yyyy-MM-dd'T'HH:mm:ss")
}

But my question is how can I use this date in my below SQL

INSERT into [dbo].ORTCommandPropertyData
([CommandID],[CommandPropertyID],[CommandTypeID],[PropertyValue],[LastUpdated] )
VALUES ('${JDBCRequestForCommandInCoolingOff#ResponseAsXml#//Results[1]/ResultSet[1]/Row[1]/COMMANDID[1]}',61,81,'2016-01-27T10:00:00',NULL);

Thanks,

  • Thanks for your time.

     

    I am trying to add date but script througs error. here is the code. I am sorry I am very new to Groovy (even in any prog language)

     

    import groovy.time.TimeCategory
    import com.eviware.soapui.support.XmlHolder
    
    use ( TimeCategory )
    {
    	def toDate = new Date()
    	def tomDate = new Date() + 1.days
    	def a = toDate.format("yyyy-MM-dd'T'HH:mm:ss")
    	def b = tomDate.format("yyyy-MM-dd'T'HH:mm:ss")
    	log.info a
    	log.info b
    	
    }
    	
    	testRunner.testCase.setPropertyValue ("Date1" , a)
    	testRunner.testCase.setPropertyValue ("Date2" , b)
  • go2khurram's avatar
    go2khurram
    9 years ago

    I manage to save the date now in custome propertied by using below code , now the in the next step I will try to use custome property in SQL Query. 

    import groovy.time.TimeCategory
    import com.eviware.soapui.support.XmlHolder
    
    use ( TimeCategory )
    {
    	def toDate = new Date()
    	def tomDate = new Date() + 1.days
    	def a = toDate.format("yyyy-MM-dd'T'HH:mm:ss")
    	def b = tomDate.format("yyyy-MM-dd'T'HH:mm:ss")
    	testRunner.testCase.setPropertyValue ("CDate" , toDate.format("yyyy-MM-dd'T'HH:mm:ss"))
    	testRunner.testCase.setPropertyValue ("TMDate" , tomDate.format("yyyy-MM-dd'T'HH:mm:ss"))
    	
    }
  • nmrao's avatar
    nmrao
    Champion Level 3
    did you set the date in custom property of a test case?
    • go2khurram's avatar
      go2khurram
      Contributor

      Thanks for your time.

       

      I am trying to add date but script througs error. here is the code. I am sorry I am very new to Groovy (even in any prog language)

       

      import groovy.time.TimeCategory
      import com.eviware.soapui.support.XmlHolder
      
      use ( TimeCategory )
      {
      	def toDate = new Date()
      	def tomDate = new Date() + 1.days
      	def a = toDate.format("yyyy-MM-dd'T'HH:mm:ss")
      	def b = tomDate.format("yyyy-MM-dd'T'HH:mm:ss")
      	log.info a
      	log.info b
      	
      }
      	
      	testRunner.testCase.setPropertyValue ("Date1" , a)
      	testRunner.testCase.setPropertyValue ("Date2" , b)
      • go2khurram's avatar
        go2khurram
        Contributor

        I manage to save the date now in custome propertied by using below code , now the in the next step I will try to use custome property in SQL Query. 

        import groovy.time.TimeCategory
        import com.eviware.soapui.support.XmlHolder
        
        use ( TimeCategory )
        {
        	def toDate = new Date()
        	def tomDate = new Date() + 1.days
        	def a = toDate.format("yyyy-MM-dd'T'HH:mm:ss")
        	def b = tomDate.format("yyyy-MM-dd'T'HH:mm:ss")
        	testRunner.testCase.setPropertyValue ("CDate" , toDate.format("yyyy-MM-dd'T'HH:mm:ss"))
        	testRunner.testCase.setPropertyValue ("TMDate" , tomDate.format("yyyy-MM-dd'T'HH:mm:ss"))
        	
        }