It's not entirely clear what you're trying to do.
If your code needs to know whether it's Thursday, that's really easy using
getDay
, which gives you the day of the week:if (new Date().getDay() === 4) { // It's Thursday }
The day numbers start with
0
= Sunday.If your code needs to find the next Thursday starting on a given date:
var dt = /* ...the start date... */; while (dt.getDay() !== 4) { dt.setTime(dt.getTime() + 86400000)) // 86400000 = 1 day in milliseconds }
or of course without the loop:
var dt = /* ...the start date... */; var days = 4 - dt.getDay(); if (days < 0) { days += 7; } dt.setTime(dt.getTime() + (days * 86400000));
If you have a Thursday already and you need to know the date for the next Thursday:
var nextThursday = new Date(thisThursday.getTime() + (86400000 * 7));