Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing two time variables with jquery

This is my jQuery code. In this code #StartTime and #EndTime is form input tag id's.

The getting time format is 00:00 AM/PM.

The var starttimeval and endtimeval contain values of getting start and end time.

How do I compare these two times, example: if(starttimeval < endtimeval){alert(message);}

  $(function() {
    $('#StartTime').datetimepicker({
        datepicker : false,
        format : 'g:i A'
    });
    $('#EndTime').datetimepicker({
        datepicker : false,
        format : 'g:i A'

    });
     var starttimeval=  $("#StartTime").val();
     var endtimeval= $("#EndTime").val();

      });

this is my form image.its show the time selection using datetimepicker plugin.

i want only time compare functionality. example getting value of starttimeval=8:00 PM and endtimeval=9:00 AM

like image 704
nmkkannan Avatar asked Apr 15 '14 14:04

nmkkannan


1 Answers

Well, have you tried something like this :

var dateBegin = $('StartTime').datepicker('getDate').getTime():
var dateEnd = $('EndTime').datepicker('getDate').getTime();
if (dateBegin == dateEnd)
   // some stuff

Seen in the doc. (I assume you are using datetimepicker from jquery ui)

like image 143
Larta Avatar answered Oct 06 '22 07:10

Larta