Trying to get second coming Thursday (e.g.) using moment.js
. Not this Thursday. The next one. The date in 2 Thursdays.
I have tried
moment().add(1, 'week').day(4)
which just fetches Thursday of the next week (only works if current weekday is before Thursday)
Any ideas?
"which just fetches Thursday of the next week (only works if current weekday is before Thursday)"
It's happening because .add(1, 'week') just adds 7 days and gets you the next week date and you are fetching 4th day of that week. Below code will work for your case perfectly.
Not sure about using moment.js, but in plain js next Thursday is given by:
For the following Thursday, just add 7 days. Presumably if the current day is Thursday, want the Thursday in two weeks so:
Or encapsulated in a function with some tests: