Laravel count days within a period of dates

0

I have 2 calendars, one issue date and another expiration date, I want to know how many days are between the dates placed and save it in a variable.

For example, if my issue date is 02/07/2017 and my expiration date is 12/07/2017 the number of days between the issue date and the expiration date are 10 .

<div class="col-lg-2 col-sm-2 col-md-2 col-xs-12">
          <div class="form-group"> 
        <label class="control-label" for="date">Fecha De Emision</label>
        <input class="form-control" id="fecha_emision" name="fecha_emision" placeholder="AAAA/MM/DD" type="text"/>
      </div>
         </div>
      <div class="col-lg-2 col-sm-2 col-md-2 col-xs-12">
          <div class="form-group"> 
        <label class="control-label" for="date">Fecha De Expiracion</label>
        <input class="form-control" id="fecha_expiracion" name="fecha_expiracion" placeholder="AAAA/MM/DD" type="text"/>
      </div>
         </div>
    
asked by Jorge Ortiz 03.07.2017 в 00:01
source

1 answer

1

For PHP : Use Carbon .

Example:

$fechaEmision = Carbon::parse($req->input('fecha_emision'));
$fechaExpiracion = Carbon::parse($req->input('fecha_expiracion'));

$diasDiferencia = $fechaExpiracion->diffInDays($fechaEmision);

For JS : Use Moment .

Example:

var fechaEmision = moment(document.getElementById('fecha_emision').value, 'YYYY/MM/DD');
var fechaExpiracion = moment(document.getElementById('fecha_expiracion').value, 'YYYY/MM/DD');

var diasDiferencia = fechaExpiracion.diff(fechaEmision, 'days');
    
answered by 03.07.2017 / 00:10
source