How to compare two input one type datetime and another datetime-local?

0

This is the comparison, since it does not allow me to compare apparently to be two types of input different since I do it with two type date and it works, and I do not do so because in input type datetime I show the date of the system and in the other input I select the date wanting to compare that the income is less than the delivery.

<div class="form-group" >
    <div class="">
        <label for="">Fecha de Ingreso</label>
        <input class="form-control" type="datetime" disabled="true" 
               id="fecha" name="fecha" value="<?php echo date("d/m/Y H:i:s");?>" size="10"/>
        <span class="help-block"></span>
    </div>
</div>

<div class="form-group">
    <div class="">
        <label style="color: #000">Fecha y Hora de Entrega</label>
        <input class="form-control" type="datetime-local"  name="fecha_ent" id="fecha_ent" style="" required/>
        <span class="help-block"></span>
    </div>
</div> 

Here I compare them with JavaScript , and always shows the error message:

fecha_ing1 = $('#fecha').val();
fecha_ent = $('#fecha_ent').val();
mensajero = $('#mensajero').val();
solicita = $('#solicita').val();
contacto = $('#contacto').val();
if (fecha_ent == null || fecha_ent.length == 0 || /^\s+$/.test(fecha_ent) || fecha_ent > fecha_ing1) {
  var delay = alertify.get('notifier', 'delay');
  alertify.alert("Error", "Digita la fecha y hora Completa y la real");
  return false
}
    
asked by somfyras 19.07.2018 в 16:51
source

1 answer

1

Try converting both dates to the object of type Date of Javascript , and then compare them:

fecha_ing1 = new Date($('#fecha').val());
fecha_ent = new Date($('#fecha_ent').val());

mensajero = $('#mensajero').val();
solicita = $('#solicita').val();
contacto = $('#contacto').val();
if (fecha_ent == null || fecha_ent.length == 0 || /^\s+$/.test(fecha_ent) || fecha_ent > fecha_ing1) {
  var delay = alertify.get('notifier', 'delay');
  alertify.alert("Error", "Digita la fecha y hora Completa y la real");
  return false
}
    
answered by 19.07.2018 в 17:18