Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 18, 2019 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/d0b2293fa7955919b96e2a57d805461a to your computer and use it in GitHub Desktop.
Save parzibyte/d0b2293fa7955919b96e2a57d805461a to your computer and use it in GitHub Desktop.
<?php
/*
Hacer ciclos con fechas para ir desde un período
a otro, iterando día a día usando strtotime y date
@author parzibyte
*/
#Definir rangos de fechas
$fechaInicio = "2019-03-18";
$fechaFin = "2019-03-25";
# Fecha como segundos
$tiempoInicio = strtotime($fechaInicio);
$tiempoFin = strtotime($fechaFin);
# 24 horas * 60 minutos por hora * 60 segundos por minuto
$dia = 86400;
while($tiempoInicio <= $tiempoFin){
# Podemos recuperar la fecha actual y formatearla
# Más información: http://php.net/manual/es/function.date.php
$fechaActual = date("Y-m-d", $tiempoInicio);
printf("Fecha dentro del ciclo: %s\n", $fechaActual);
# Sumar el incremento para que en algún momento termine el ciclo
$tiempoInicio += $dia;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment