-
-
Save parzibyte/140fb3aab79c8584372079823f1f380d 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 hora a hora usando strtotime y date | |
@author parzibyte | |
*/ | |
# Definir rangos de fechas. | |
# Nota: podríamos definirlas sin horas, pero es mejor ser explícitos | |
$fechaInicio = "2019-03-18 00:00:00"; | |
$fechaFin = "2019-03-21 00:00:00"; | |
# Fecha como segundos | |
$tiempoInicio = strtotime($fechaInicio); | |
$tiempoFin = strtotime($fechaFin); | |
#60 minutos por hora * 60 segundos por minuto | |
$hora = 3600; | |
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 H:i:s", $tiempoInicio); | |
printf("Fecha y hora dentro del ciclo: %s\n", $fechaActual); | |
# Sumar el incremento para que en algún momento termine el ciclo | |
$tiempoInicio += $hora; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment