zsousa
8 years agoContributor
Solved
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 ?
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)