Re: Tratamiento de fechas MySQL

From: Date: Sun, 16 Jan 2005 12:26:20 +0000
Subject: Re: Tratamiento de fechas MySQL
References: 1 2 3 4 5 6  Groups: php.general.es 
Request: Send a blank email to general-es+get-53040@lists.php.net to get a copy of this message
Lo reenvio de nuevo, corregido el error que havia: <?php // Para el que quiera usar classes class date_format { var $date_in; var $date_out; function date_format($date_in,$date_out) {
       $this->date_in  = $date_in;
       $this->date_out = $date_out;
} function in($date) {
       if (($timestamp = strtotime($date)) === -1) {
           return -1;
       }
       return date($this->date_in,$timestamp);
} function out($date) {
       if (($timestamp = strtotime($date)) === -1) {
           return -1;
       }
       return date($this->date_out,$timestamp);
} } $d = &new date_format('Y-m-d','d-m-Y'); $fecha = '10/10/2005'; echo('<br> Usando classes:'); $d_in = $d->in($fecha); echo('<br>'.$d_in); $d_out = $d->out($d_in); echo('<br>'.$d_out); //Para el que quiera usar funciones: define('DATE_IN','Y-m-d'); define('DATE_OUT','d-m-Y'); function date_in($date) { if (($timestamp = strtotime($date)) === -1) {
           return -1;
       }
   return date(DATE_IN,$timestamp);   }
function date_out($date) { if (($timestamp = strtotime($date)) === -1) {
           return -1;
       }
   return date(DATE_OUT,$timestamp);   }
$fecha = '10/10/2005'; echo('<br> Usando funciones:'); $d_in = date_in($fecha); echo('<br>'.$d_in); $d_out = date_out($d_in); echo('<br>'.$d_out); // Para los que no quieren usar ni classes ni funciones $date_in = 'Y-m-d'; $date_out = 'd-m-Y'; $fecha = '10/10/2005'; echo('<br> Ni classes ni funciones:'); $d_in = date($date_in,strtotime($fecha)); echo('<br>'.$d_in); $d_in = date($date_out,strtotime($fecha)); echo('<br>'.$d_in); ?> Josep Maria Aribau Cano jm@infodos.com

« previous php.general.es (#53040) next »