JSFiddle - React, Tailwind, and code Playground

by superbDeveloper

JavaScript

function dateLenCheckFunc(dateItem) {
        if (dateItem == null) { return; }
        return (dateItem.toString().length == 2) ? dateItem : ("0" + dateItem);
    }
    
    Date.parseAll = Date.prototype.parseAll = function(strDate){
        var m = /([0-9]{4})([0-9]{2})([0-9]{2})/.exec(strDate);
        return new Date(m[1],(m[2]-1),m[3]);
    };
    
    
    var curVal = "2012-05-03";
    var curTmpDate = "2012-05-04";
    
    var curValDate = new Date(Date.parseAll(curVal.replace(/-/g, '')));
    var curDate = (isNaN(Date.parseAll(curTmpDate.replace(/-/g, ''))) == true) ? new Date() : new Date(Date.parseAll(curTmpDate.replace(/-/g, '')));
    
    //compare by converting date to number
    var curValDateNum = parseInt(curValDate.getFullYear() + "" + dateLenCheckFunc(curValDate.getMonth()) + "" +  dateLenCheckFunc(curValDate.getDate()));
    
    var curDateNum = parseInt(curDate.getFullYear() + "" + dateLenCheckFunc(curDate.getMonth()) + "" +  dateLenCheckFunc(curDate.getDate()));
    
    if (curValDateNum > curDateNum) {
    //cur date must be a Relative Past and Today's date
       alert("cur date must be a Relative Past and Today's date");
    }else{
       alert("working");
    }