Hi,
I have two dates in javascript:
var first ='21/10/2012'; var second ='31/11/2013';
i would like make:
if(first > second){//...}
how is the best way for doing this?
Refer
http://www.c-sharpcorner.com/UploadFile/8911c4/how-to-compare-two-dates-using-javascript/
This way
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } </style> </head> <body> Enter dates in dd/MM/yyyy format:<hr /> From: <input type="text" id="txtFrom" value="03/02/2014" /> To: <input type="text" id="txtTo" value="01/02/2014" /> <input type="button" value="Compare" onclick="Compare()" /> <script type="text/javascript"> function Compare() { var from = document.getElementById("txtFrom").value; var to = document.getElementById("txtTo").value; var dtFrom = new Date(parseInt(from.split('/')[2]), parseInt(from.split('/')[1]) - 1, parseInt(from.split('/')[0])); var dtTo = new Date(parseInt(to.split('/')[2]), parseInt(to.split('/')[1]) - 1, parseInt(to.split('/')[0])); if (dtFrom < dtTo) { alert("From date is less than To date."); } else if (dtFrom > dtTo) { alert("From date is greater than To date."); } else { alert("From date is equal to To date."); } } </script> </body> </html>
Demo
© COPYRIGHT 2024 ASPSnippets.com ALL RIGHTS RESERVED.