Find whether current time falls between two time?

function getTodaysDate(){
          var d = new Date();
          var month = d.getMonth() + 1;
          var day = d.getDate();
          var today = d.getFullYear() + '-' +
                      (('' + month).length < 2 ? '0' : '') + month + '-' +
                      (('' + day).length = allTimings[1] && allTimings[0] < allTimings[2]) {
          return today;
}

function getTimings(startTime, endTime){
         var today = getTodaysDate();
         var startDateTime = today + " " + startTime;
         var endDateTime = today + " " + endTime;
         var now = new Date();
         var start = new Date(startDateTime).getTime();
         var end = new Date(endDateTime).getTime();
         now = now.getTime();
         return [now, start, end];
}

var startTime = "10:20";
var endTime = "14:35";
var allTiming = getTimings(startTime, endTime);//will return 3 timings [0]->current timestamp, [1]->startTime                        timestamp, [2]->endTime timestamp.
if (allTiming[0] >= allTiming[1] && allTiming[0] < allTiming[2] ) {
         console.log("Time falls inbetween two times");
}else{
         console.log("...");
}


Leave a Reply