Diferencias entre fechas con PHP
ctg | 16 Febrero, 2007 00:08Clase simple, en PHP, para calcular diferencias entre fechas.
<?php
// Class for get the differences in seconds, min, hours, days and weeks between two dates
// Notes: If you only need the difference in days, assure that seconds, min and hours are 0
class TimeSpan
{
var $diff_seconds;
var $diff_minutes;
var $diff_hours;
var $diff_days;
var $diff_weeks;
// Date format: YYYYMMDDHHmmSS
function TimeSpan($date1, $date2)
{
// Transform to Unix timestamp
$epoch_1
= mktime( substr($date1,8,2), substr($date1,10, 2), substr($date1,12,
2), substr($date1,4, 2), substr($date1,6, 2), substr($date1,0, 4) );
$epoch_2
= mktime( substr($date2,8,2), substr($date2,10, 2), substr($date2,12,
2), substr($date2,4, 2), substr($date2,6, 2), substr($date2,0, 4) );
$this->diff_seconds = $epoch_1 - $epoch_2;
$this->diff_minutes = floor($this->diff_seconds/60);
$this->diff_hours = floor($this->diff_seconds/3600);
$this->diff_days = floor($this->diff_seconds/(3600*24));
$this->diff_weeks = floor($this->diff_seconds/(3600*24*7));
}
// Gets the seconds
function getDiffSeconds()
{
return $this->diff_seconds;
}
// Gets the minutes
function getDiffMinutes()
{
return $this->diff_minutes;
}
// Gets the hours
function getDiffHours()
{
return $this->diff_hours;
}
// Gets the days
function getDiffDays()
{
return $this->diff_days;
}
// Gets the weeks
function getDiffWeeks()
{
return $this->diff_weeks;
}
}
?>
Posted in
PHP .
Comentario: (0).
Retroenlaces:(0).
Enlace
«Next post |
Previous post»