检查给定日期是否在工作周内(周一至周五)

时间:2016-10-11 16:43:29

标签: javascript date

如何检查并查看给定日期,我们称之为(dateX)是否在(当前日期)工作周内(周一至周五)

逻辑:

If (dateX is within the present work week of Monday-Friday) {  return true }
Else { return false }

//Date Format is: yyyy-mm-dd
//dateX = 2016-10-11
If (2016-10-11 is within 2016-10-10 to 2016-10-14) { then return true }
Else { return false }

1 个答案:

答案 0 :(得分:0)

你可以尝试这个

if(datebetweenCheck("10/09/2016","10/10/2016","12/09/2016"))
{
    alert("Yes");
}
else
{
    alert("No");
}

function datebetweenCheck(from,to,current) {

    var fromDate,toDate,currentDate;
    fromDate = Date.parse(from);
    toDate = Date.parse(to);
    currentDate = Date.parse(current);

    if((currentDate <= toDate && currentDate >= fromDate)) {
        return true;
    }
    return false;
}