-
-
Save parzibyte/d0b2293fa7955919b96e2a57d805461a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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