cancel
Showing results for 
Search instead for 
Did you mean: 

Get the date of next Sunday

SOLVED
Highlighted
Occasional Contributor

Get the date of next Sunday

Hello all,

 

I want to get the date of the next Sunday, of every week to be entered in a specific field. I have tried aqConvert.DateTimeToFormatStr(aqDateTime.AddDays(7), '%d.%m.%Y') as Sunday being the 7th day of the week but my syntax is wrong. Since I am very new at this, any help would be much appreciated.

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Get the date of next Sunday

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);

}

Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
5 REPLIES 5
Community Hero

Re: Get the date of next Sunday

AddDays requires a parameter indicating the date to add days to.  Try

 

aqConvert.DateTimeToFormatStr(aqDateTime.AddDays(aqDateTime.Now(),7), '%d.%m.%Y')


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Occasional Contributor

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

Community Hero

Re: Get the date of next Sunday

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);

}

Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Occasional Contributor

Re: Get the date of next Sunday

Thank you!

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

Community Hero

Re: Get the date of next Sunday

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


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
New Here?
Join us and watch the welcome video:
API Testing Mistake #2
APITestingMistake#2
Top Kudoed Authors