Forum Discussion

zsousa's avatar
zsousa
Contributor
8 years ago
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 th...
  • gilugopi's avatar
    gilugopi
    8 years ago

    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)