0

I want to set week day index (not month day) in time

for example:

"2021-11-01T10:50:02+04:00" should be converted to "2021-11-08T10:50:02+04:00"

"2021-11-02T10:50:02+04:00" should be converted to "2021-11-08T10:50:02+04:00"

and so on

basically my task is to convert any week day to friday

1 Answer 1

2

So update myDate to Friday (in current week), you could do something like this:

var dayToSet = 5; // Friday
var currentDay = myDate.getDay();
var distance = dayToSet - currentDay;
myDate.setDate(myDate.getDate() + distance);
1
  • 1
    Noting that this assumes that the week starts on Sunday. It may also start on Monday, Friday or Saturday depending on local rules.
    – RobG
    Nov 13, 2021 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.