Compare Date & Time in JQuery -


i want message date comparing in jquery. for example: have text box value 04/01/2013 13:15:32 filled userend. , current date time in jquery variable 04/01/2013 18:30:12 if text box value less current datetime show message:

function foo(){     usrdate = jquery("#txtdate").val(); //getting user input date time      currentdate = new date(); //system current date     currentmonth = currentdate.getmonth() + 01;     currentday = currentdate.getdate();     currentyear = currentdate.getfullyear();     currenthours = currentdate.gethours();     currentminutes = currentdate.getminutes();     currentseconds = currentdate.getseconds();      currentcpdatetime = currentmonth + "/" + currentday + "/" + currentyear + " " + currenthours + ":" + currentminutes + ":" + currentseconds;        if (usrdate > currentcpdatetime ) {        alert("you can not choose date greater current");        }    else {       alert("valid date");  } } 

each time wrong result. :(

why not use framework jquery ui , can below

your html

<p>date: <input type="text" id="datepicker" /></p> <input type="button" id="checkdate" value="checkdate"> 

your js

$(document).ready(function(){     $( "#datepicker" ).datepicker();     $('#checkdate').bind('click',function(){         var mydate = $('#datepicker').datepicker( "getdate" );         var curdate = new date();          if(curdate>mydate){             alert('current date high');         }         else{             alert('selected date high');         }     }); }); 

check out example @ live fiddle


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -