on 07-23-2007 11:34 AM
I am writing a javascript for comparison of two dates such that the first date should be a previous date than the second date.
Since I am getting my date from a IPicker, it returns a date of the format "dd/mmmyyyy" (e.g)23/jul/2007
Now how can I compare the two dates of the above format
The following is my code which works if the date format is dd/mm/yyyy
var fromdate = document.frmdate.txtfromdate.value.split('/');
var fromdate1 = new Date(fromdate[0]'/'fromdate[1]'/'fromdate[2]);
var todate = document.frmdate.txttodate.value.split('/');
var todate1 = new Date(todate[0]'/'todate[1]'/'todate[2]);
if(fromdate1<todate1)
{
return true;
}
else
{
alert("The FromDate should be a past date than the ToDate");
return false;
}
Hello,
Create a function with a switch structure
function getMonth(month) {
switch (month) {
case 'jan':
month='01';
break;
case 'feb':
month='02';
break;
case 'mar':
month='03';
break;
//and so on.....
}
}
Then, your main code is :
var fromdate = document.frmdate.txtfromdate.value.split('/');
var fromdate1 = new Date(fromdate[0]+'/'+getMonth(formdate[1])+'/'+fromdate[2]);
var todate = document.frmdate.txttodate.value.split('/');
var todate1 = new Date(todate[0]+'/'+getMonth(formdate[1])+'/'+todate[2]);
if(fromdate1<todate1)
{
return true;
}
else
{
alert("The FromDate should be a past date than the ToDate");
return false;
}>
Reward if helpful!
Regards,
Julien.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.