Last active
February 6, 2017 21:48
-
-
Save daniel7byte/755bb01875a7182c5b495a9c4f473b8f to your computer and use it in GitHub Desktop.
Author: josealvaradoo
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 | |
/* __________________________________________________________________ | |
/* | |
/* Fechas obtenidas desde la base de datos y desde el formulario | |
/* enviado por el usuario | |
/* _______________________________________________________________ */ | |
$dateDataBase = "2/8/2014"; | |
$dateMinUser = "3/11/2012"; | |
$dateMaxUser = "5/12/2016"; | |
/* __________________________________________________________________ | |
/* | |
/* Con esta funcion transformamos las fechas tipo string Mes/Dia/Año | |
/* en formato unix (segundos) | |
/* _______________________________________________________________ */ | |
function humanDateToUnix($date) { | |
$month = explode("/", $date)[0]; | |
$day = explode("/", $date)[1]; | |
$year = explode("/", $date)[2]; | |
$date = $month . "-" . $day . "-" . $year; | |
$phpdate = strtotime(date($date)); | |
return ($phpdate); | |
} | |
/* __________________________________________________________________ | |
/* | |
/* Testeando que funcione | |
/* _______________________________________________________________ */ | |
echo "Tiempo actual <br>"; | |
echo time(); | |
echo "<br><br>Tiempo de fecha 1 ({$dateDataBase})<br>"; | |
echo humanDateToUnix($dateDataBase); | |
echo "<br><br>Tiempo de fecha 2 ({$dateMinUser})<br>"; | |
echo humanDateToUnix($dateMinUser); | |
echo "<br><br>Tiempo de fecha 3 ({$dateMaxUser})<br>"; | |
echo humanDateToUnix($dateMaxUser); | |
echo "<br><br><br>"; | |
/* __________________________________________________________________ | |
/* | |
/* Ejemplo de lógica de rango | |
/* _______________________________________________________________ */ | |
echo "Virificando que Fecha 1 esté dentro del rango dado por el usuario: <br>"; | |
if(humanDateToUnix($dateMinUser) >= humanDateToUnix($dateDataBase) AND humanDateToUnix($dateDataBase) <= humanDateToUnix($dateMaxUser)) { | |
echo "Si está dentro del rango."; | |
} else { | |
echo "No está dentro del rango"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment