Click here to Skip to main content
15,891,621 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Expert ,

In asp.net Nridubai website,there are 2 date control designed using javascript.

Both these control attached with textbox control.and it shows date in textbox in dd/mm/yy format.

i have to compare these two date in javascript.

My javascript code for comaprison is

var startDate=document.getElementById("<%=txtStartDate.ClientID%>").value;
var endDate=document.getElementById("<%=txtEndDate.ClientID%>").value;
var date1 = new Date(startDate);
var date2 = new Date(endDate);

 if(date1 > date2)
      {
                alert("End Date must be greater than start date");
                
                 return false;
      }


but above code compare 2 dates according to mm/dd/yyyy format.
and i wants these comparison in dd/mm/yyyy format.

Thanks in advance..............
Posted
Updated 28-Jun-12 22:56pm
v2

 
Share this answer
 
Comments
udusat13 20-Oct-11 7:15am    
Thanksssss.....
Anuja Pawar Indore 20-Oct-11 8:03am    
Welcome :)
The Date constructor[^] does not use dd/mm/yyyy but mm/dd/yyyy.

Use
JavaScript
var arrStartDate = startDate.value.split("/");
var date1 = new Date(arrStartDate[2], arrStartDate[1], arrStartDate[0]);
var arrEndDate = endDate.value.split("/");
var date2 = new Date(arrEndDate[2], arrEndDate[1], arrEndDate[0]);

to get the correct date objects from the strings.
 
Share this answer
 
Comments
udusat13 20-Oct-11 7:15am    
thankssss this code is working fine for me.......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900