How to Know The Selected Date is Previous in javascript
-
Hi all Iam New to javascript can you help me how to check the selected date is previous one? eg:today is 14/8/2011 and i selected 12/8/2011 in a javascript calender i want to validate the selected date is previus one is it possible? Please Help me Arunkumar.T :((
-
Hi all Iam New to javascript can you help me how to check the selected date is previous one? eg:today is 14/8/2011 and i selected 12/8/2011 in a javascript calender i want to validate the selected date is previus one is it possible? Please Help me Arunkumar.T :((
Do you mean you want to make sure the selected date is BEFORE todays date? If thats all you need then a simple DateDiff and look for a +ve or -ve number depending on whether you put the latestdate first or second; http://ditio.net/2010/05/02/javascript-date-difference-calculation/[^]
Dave Find Me On: Web|Facebook|Twitter|LinkedIn
Folding Stats: Team CodeProject
-
Hi all Iam New to javascript can you help me how to check the selected date is previous one? eg:today is 14/8/2011 and i selected 12/8/2011 in a javascript calender i want to validate the selected date is previus one is it possible? Please Help me Arunkumar.T :((
/************************************************
function: CompareDates
Arguments: fromdate : type 'String' : format : DD/MM/YYYY
Arguments: todate : type 'String' : format : DD/MM/YYYY
Returns: Number value
if value = 1 : fromdate comes before todate
if value = 0 : fromdate and todate are same
if value = -1 : fromdate comes after todate
*************************************************/
function CompareDates(fromdate,todate) {
// Assuming the date format = DD/MM/YYYY
// modify following block if your date format is different
// new Date(year,month,day)
frmdt = new Date(fromdate.substring(6,10),fromdate.substring(3,5)-1,fromdate.substring(0,2));
todt = new Date(todate.substring(6,10),todate.substring(3,5)-1,todate.substring(0,2));if ( todt.getTime() > frmdt.getTime() ) { return 1; } else if( todt.getTime() == frmdt.getTime() ) { return 0; } return -1;
}
Thanks & Regards, Niral Soni