Skip to content
Advertisement

Can I add number of days to the (dayoftheweek) to get another day?

I have a date and from that I find the dayoftheweek . Lets say the day I found is Tuesday . I have a variable that has duration . Lets say the duration is 5 days . Will I be able to add 5 to Tuesday and get Saturday as the answer . Tuesday should be considered as day 1 and saturday as day 5.

JavaScript

Is this correct?

JavaScript

If not how do I do that ?

Advertisement

Answer

If you want Saturday, add 4 days.

JavaScript

If all you want to do is add a number of days to a day of week and get another day of week then use a modulo operation.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement