Sandyapitester
8 years agoFrequent Contributor
Date format - Need to get the current date from 10 date before date
Hi All,
Need to pass the request parameter value is current date from 10/20/30 days before
[
"25/08/2017"]
when ever execute the API need to pass the current date from 10/20/30 days before date
Tried:
def today = new Date().format("MM/dd/yyyy")
log.info today
def tendaysbefore = today -10
log.info tendaysbefore
response :
Mon Sep 04 19:43:35 IST 2017:INFO:09/04/2017
Mon Sep 04 19:43:35 IST 2017:INFO:09/04/2017
But I need 10 days before from the current date.
looking for your valuable response and update
You are subtracting too late. You need to subtract before you convert / format to a string. Try this:
def today = new Date() def tenDaysAgo = today - 10 log.info today.format("MM/dd/yyyy") log.info tenDaysAgo.format("MM/dd/yyyy")