Búsqueda


Categorías

C# [15]
PHP [6]
Zend [1]
FileMaker [1]
.NET [6]
CVS [3]
General [9]
Javascript [2]
Paypal [1]
.NET Compact Framework [3]
C++ [1]
mysql [4]
Linux [1]

Últimos post

Dónde guardar los archivos de configuración en ClickOnce
phpinfo: Valores en error_reporting
Notes about Zend Server and Zend Studio setup
What's new in C# 4
Resolving a 'sticky tag is not a branch' error
Resumen del CodeCamp
CodeCamp Tarragona 2009
Acerca de la calidad del código
ClickOnce en Linux
Programando en PHP (y con CVS) en Visual Studio 2008

Sindicación

RSS 0.90
RSS 1.0
RSS 2.0
Atom 0.3

Diferencias entre fechas con PHP

ctg | 16 Febrero, 2007 00:08

Clase 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»

Comentarios

Deja un comentario
















Primer mes del año: