I think i'm mainly having a brain fart. I just want to fast forward a Date()
until a specific day of the week and then get the Month, Day, Year for that.
E.g. today is 09/03/10 but i want a function (nextSession()
) to return 09/08/10 (next wednesday).
How would I do this? The best thing I can think of is add a day to setDate()
until getDay()
== 3, but it's sorta ugly...
P.S. jQuery is cool too.
function nextSession(date) { var ret = new Date(date||new Date()); ret.setDate(ret.getDate() + (3 - 1 - ret.getDay() + 7) % 7 + 1); return ret; }
This one will set date to next Wednesday. If it is already Wednesday, result will be one week later from given date.
EDIT: Added possibility of calling function without a parameter: nextSession()
- it returns next session date from today
Use the DateJS library.
Date.parse('next wednesday');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With