Forum Discussion

Sandyapitester's avatar
Sandyapitester
Frequent Contributor
8 years ago

How to create datetime string in soapui using groovy with +10 days or -10 days

Hi All,

 

Am able to get the current time using groovy but need the timestamp 10days and after days format

 

 

Groovy scripting:

 

today = new Date()-10 .format("yyyy-MM-dd HH:mm:ss.SSSSS Z")
log.info today

 

but need the timestamp + 10 days and after 10 days format 

 

 

Please share the solution and suggestion 

 

  • groovyguy's avatar
    groovyguy
    Community Hero

    Here's a sample groovy script that you can use to offset by hours/days/etc.

     

    def now = Calendar.getInstance()
    String TimeStamp;
     
    // Can offset by various fields
    // HOUR
    // DAY_OF_WEEK
    // etc
    now[HOUR] = now[HOUR] + offset;
    
    Timestamp = now.format("yyyy-MM-dd'T'HH:mm:ss.SSS");
      • Sandyapitester's avatar
        Sandyapitester
        Frequent Contributor

        Hi All,

         

        So far in my suite property have used ${= new Date().format('yyyy-MM-dd')}

         

        this will help us to get the current date and time 

         

        but now I need to get the date current date + 2 or -2

         

        I tried like

         

        So far in my suite property have used ${= new Date().format('yyyy-MM-dd, +2')}

         

        but it's not working.

         

        Please share the  imput