Forum Discussion

mioani's avatar
mioani
Occasional Contributor
6 years ago

Re: Get the date of next Sunday

Thank you so much for your reply.

What i'm trying to do here is to get the date of next Sunday, no matter what day it is of the week. i.e tomorrow if i play the test again, the date fetched to be next Sunday.

The solution of your reply will give me the seventh day from today any day, and I want the date by default to be always Sunday, without updating my test.

Thank you again

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Then your code is going to need to be longer than single line.  

     

    You're going to need to know

     

    1) What the current day of the week is

    2) How many days until Sunday that is

     

    So...

     

    function getNextSunday(currentDate){
    
        var currentDOW = aqDateTime.GetDayOfWeek(currentDate);
        var daysToAdd = 8-currentDOW;
        return aqDateTime.AddDays(currentDate, daysToAdd);
    
    }
    • mioani's avatar
      mioani
      Occasional Contributor

      Thank you!

      Is there any way I can use this in a keyword test?

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Yes.... it's a script method to return the date.  Just use the "Run Script Routine" operation.