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");
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.