Created
February 9, 2012 12:19
-
-
Save wescleymatos/1779599 to your computer and use it in GitHub Desktop.
Fazer cálculo com data
This file contains hidden or 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 | |
echo 'Amanhã: ', strftime('%A', strtotime('tomorrow')); | |
// Amanhã: domingo | |
echo 'Próxima segunda: ', strftime('%d de %B de %Y', strtotime('next monday')); | |
// Próxima segunda: 01 de junho de 2009 | |
echo 'Vencimento: ', strftime('%d/%m/%Y', strtotime('+3 months')); | |
// Vencimento: 30/08/2009 | |
//------------------------------- | |
// Define os valores a serem usados | |
$data_inicial = '2009-03-23'; | |
$data_final = '2009-11-04'; | |
// Usa a função strtotime() e pega o timestamp das duas datas: | |
$time_inicial = strtotime($data_inicial); | |
$time_final = strtotime($data_final); | |
// Calcula a diferença de segundos entre as duas datas: | |
$diferenca = $time_final - $time_inicial; // 19522800 segundos | |
// Calcula a diferença de dias | |
$dias = (int)floor( $diferenca / (60 * 60 * 24)); // 225 dias | |
// Exibe uma mensagem de resultado: | |
echo "A diferença entre as datas ".$data_inicial." e ".$data_final." é de <strong>".$dias."</strong> dias"; | |
// A diferença entre as datas 23/03/2009 e 04/11/2009 é de 225 dias | |
//----------------------------------------- | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment