cancel
Showing results for 
Search instead for 
Did you mean: 

working with dates

SOLVED
zsousa
Contributor

working with dates

I am trying to get the duration between two dates using Groovy.

 

this is what I am doing

get today's date and save it to a property as "StartDate"

then after couple days elapsed I want to get the duration between the date I saved "StartDate" and today's date

 

but its not working for me, any suggestions ?

1 ACCEPTED SOLUTION

Accepted Solutions
gilugopi
Contributor

Re: working with dates

Made 2 assumptions here, change them in below script if needed.

1. Date format you use is "yyyy-MM-dd"

2. StartDate property is saved as a test case property.

 

Following goovy script should be able to give daysPassed

 

def sdf = new java.text.SimpleDateFormat("yyyy-MM-dd")
def startDateString = context.expand('${#TestCase#StartDate}')
def startDate = sdf.parse(startDateString)
def today = new Date()
def daysPassed = today.minus(startDate)

View solution in original post

2 REPLIES 2
nmrao
Community Hero

Re: working with dates

How exactly you want? format? which context does it require to be used?


Regards,
Rao.
gilugopi
Contributor

Re: working with dates

Made 2 assumptions here, change them in below script if needed.

1. Date format you use is "yyyy-MM-dd"

2. StartDate property is saved as a test case property.

 

Following goovy script should be able to give daysPassed

 

def sdf = new java.text.SimpleDateFormat("yyyy-MM-dd")
def startDateString = context.expand('${#TestCase#StartDate}')
def startDate = sdf.parse(startDateString)
def today = new Date()
def daysPassed = today.minus(startDate)

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors