I have requirement to disable tuesday and thursday on this calendar function but it should enable the current date also. Below script will disable past dates and enable only tuesday and thursday but current date is not enabled. i need to enable current date selection and only future tuesday & thursday dates only.

function datefunc(date) {var today=new Date();if (date !=null) {var yesterday=new Date();var futureDate=new Date();var today=new Date();today=today.setDate(today.getDate() - 1)yesterday=yesterday.setDate(yesterday.getDate() - 1);futureDate=futureDate.setDate(futureDate.getDate() + 1);if (date < yesterday)return true;else if (date==today || date.getDay() !=2 && date.getDay() !=4)return true;}return false;}
share|improve this question
  • Why are you minusing 1 off of today's date? (line 7)– MCMXCIIFeb 13 at 16:42
  • And what does this have to do with PHP?– MCMXCIIFeb 13 at 16:43
  • You have a very confusing question: "disable tuesday and thursday on this calendar function but it should enable the current date " then later " I need to enable current date selection and only future tuesday & thursday dates only." So which is it? Enable today and all future Tuesday and Wednesday? Disable all past dates? If today is a Tuesday or Thursday should it be enabled or disabled? What if a "future" date is a Wednesday, enable or disable it? By "disable/enable" do you mean return true each "enable" "requirement?– Mark SchultheissFeb 13 at 17:57
  • Also clarify how you want to handle conditions such as Daylight Savings Time on a given submitted date (if it IS date just before, on or just after a Daylight Savings Time change, how do you want it handled? Clarify also if you just want to compare the "date" part or include the time part also, including with the DST consideration.– Mark SchultheissFeb 13 at 18:04
  • Sorry for the confusion. My requirement is below. 1. disable past dates from selection, 2. Only enable tuesday and thursday in future weeks. 3) need to enable current day (today).. say eg. today is wednesday if i open the calendar it should enable today date and future tuesday and thursday only remaining should be disabled.. likewise for all current date.– user3715261Feb 14 at 5:21

I am going to go ahead and attempt to answer a very ambiguous question. Given that, I am only going to post something that hopefully you can work with.

First off, this date stuff is "hard" so let's leverage StackOverflow to find stuff we can work with (it MIGHT be better to use a date library but let's build from others efforts - up vote them as useful!)

Some additional information on date comparisons: http://stackoverflow.com.mevn.net/a/493018/125981

// credit here: http://stackoverflow.com.mevn.net/a/1353711/125981function isDate(d) {if (Object.prototype.toString.call(d)==="[object Date]") {// it is a dateif (isNaN(d.getTime())) { // d.valueOf() could also work// date is not validreturn false;} else {// date is validreturn true;}} else {// not a datereturn false;}}// return true if prior to yesterday, OR is today(exactly), is not tuesday, or is not thursdayfunction datefunc(date) {var today=new Date();if (isDate(date)) {var yesterday=new Date(new Date().setDate(today.getDate() - 1));var tomorrow=new Date(new Date().setDate(today.getDate() + 1));console.log(today.getTime(), yesterday.getTime(), tomorrow.getTime());if (date.getTime() < yesterday.getTime() || date.getTime()==today.getTime() || (date.getDay() !=2 && date.getDay() !=4)) {return true;}}return false;}// credit here: http://stackoverflow.com.mevn.net/a/27336600/125981// if d is dow, return that else next dowfunction currentOrNexDowDay(d, dow) {d.setDate(d.getDate() + (dow + (7 - d.getDay())) % 7);return d;}// credit here: http://stackoverflow.com.mevn.net/a/27336600/125981// if cd is dow and not d, return that else next dowfunction nextDowDay(d, dow) {var cd=new Date(d);cd.setDate(cd.getDate() + (dow + (7 - cd.getDay())) % 7);if (d.getTime()===cd.getTime()) {cd.setDate(cd.getDate() + 7);}return cd;}// a Tuesdayvar checkDate=new Date("2018-02-13T17:30:29.569Z");console.log(datefunc(checkDate));// a WednesdaycheckDate=new Date("2018-02-14T17:30:29.569Z");console.log(datefunc(checkDate));// a SundaycheckDate=new Date("2018-02-11T17:30:29.569Z");console.log(datefunc(checkDate));// Next Mondayvar d=new Date();d=currentOrNexDowDay(d, 1);//d.setDate(d.getDate() + (8 - d.getDay()) % 7);console.log(d);console.log(datefunc(d));// Next Tuesdayvar dt=new Date();dt=nextDowDay(dt, 2);console.log(dt);console.log(datefunc(dt));

share|improve this answer

    Your Answer


    By posting your answer, you agree to the privacy policy and terms of service.

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