Ask a Question

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

SOLVED
Sandyapitester
Frequent Contributor

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 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
sanj
Super Contributor

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

Here are some cool examples of how to play with Date objects using Groovy

https://examples.javacodegeeks.com/jvm-languages/groovy/groovy-date-example/

 

View solution in original post

PaulMS
Super Contributor

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

From examples in the link sanj suggested

 

new Date().plus(2).format('yyyy-MM-dd')
new Date().minus(2).format('yyyy-MM-dd')

View solution in original post

5 REPLIES 5
msiadak
Community Hero

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

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");



---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
sanj
Super Contributor

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

Here are some cool examples of how to play with Date objects using Groovy

https://examples.javacodegeeks.com/jvm-languages/groovy/groovy-date-example/

 

View solution in original post

Sandyapitester
Frequent Contributor

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

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

msiadak
Community Hero

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

Did you try the code I provided?




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
PaulMS
Super Contributor

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

From examples in the link sanj suggested

 

new Date().plus(2).format('yyyy-MM-dd')
new Date().minus(2).format('yyyy-MM-dd')

View solution in original post

cancel
Showing results for 
Search instead for 
Did you mean: