I've txtStartDate control like that format : 09.03.2012
I want to compare txtStartDate value CurrentDate. if txtStartDate bigger than CurrentDate, i want to return true. how to to this?
I've txtStartDate control like that format : 09.03.2012
I want to compare txtStartDate value CurrentDate. if txtStartDate bigger than CurrentDate, i want to return true. how to to this?
Dates in javascript suck. I recommend using this library FWIW, http://www.datejs.com/
Specifically http://code.google.com/p/datejs/wiki/APIDocumentation#compare
and related
Also see
http://code.google.com/p/datejs/wiki/APIDocumentation#parse for actually converting the text to a date object.
Reverse your dates: 20120309
, comparing is easy.
function chgDate(dte){
var pm=new String(dte.getMonth()+1);if(pm.length<2) pm='0'+pm;
var pd=new String(dte.getDate());if(pd.length<2) pd='0'+pd;
var py=dte.getFullYear();
return new Number(py+pm+pd);
}
function chgControl(dte){
dte=dte.split('.');
return new Number(dte[2]+dte[1]+dte[0]);
}
bool=(chgControl('09.03.2012')>chgDate(new Date()));
You'll want to create a Date object from the text you have. This will probably involve taking the string and splitting it up and passing it to the Date(year, month, day)
constructor. I can't tell which way round your days and months are though so I can't give you example code.
Once you've created a Date object you can compare it to the current date, which you can get using new Date()
.