0

Here is my HTML code

<div class="form-group">
    <label for="labeldate" class="col-sm-1 control-label">Time</label>
    <label for="input_fromdate" class="col-sm-2 control-label">From</label>
    <div class="col-sm-3">
        <input type="time" class="form-control" id="from_time" name="from_time" placeholder="Pick here">
    </div>
    <label for="input_todate" class="col-sm-1 control-label">To </label>
    <div class="col-sm-3">
        <input type="time" class="form-control" id="to_time" name="to_time" value="" placeholder="Pick here">
    </div>
</div>

I want to make sure that to_time is always greater than from_time. Lets take from_time:05:00 PM and to_time:04:00 PM. I tried using greater than in jquery but it doesnt work perfectly. I want this to include with my jquery validation code

Mahbubul Islam
  • 998
  • 1
  • 10
  • 24
HariPriya
  • 117
  • 1
  • 2
  • 16

1 Answers1

1

I made this simple Javascript working as you requested:

var from_time= "11:00 AM";
var to_time = "10:00 PM";

var from = Date.parse('01/01/2011 '+ from_time);
var to = Date.parse('01/01/2011 '+ to_time);

if (from > to){
   console.log ("From greater than To!");
} else {
   console.log ("To greater than from!")
}
Fabio Marzocca
  • 1,573
  • 16
  • 36