Hola,
Hoy acabo de subir mi web a internet (de momento en un hosting de prueba gratuita) y me tira el siguiente error:
Fatal error: Call to undefined method haceTanto::diff() in /home/dvezeogs/public_html/config.php on line 49
Lo que hago es capturar la fecha de la base de datos y ponerla en el formato: "5 años, 4 meses y 19 días". Abajo os comento la linea que da el error.
Espero que me podáis ayudar. Muchas gracias de antemano.
Os pongo como llamo a la clase:
Código PHP:
Ver original<?php $hace = new haceTanto($row["fecha"]); ?>
<span class="fichanegrita"><?php echo $lang_seccion_fichas['edad'] ?>:</span> <?php echo ''.$hace; ?><br/><br/>
Y os pongo el código completo de la clase:
Código PHP:
Ver original//Clase para obtener la fecha para la ficha de los animales
class haceTanto extends DateTime {
protected $strings = array( 'y' => array('1 año, ', '%d años, '), 'm' => array('1 mes y', '%d meses y'), 'd' => array('1 día', '%d dias'), );
public $profundidad;
public function __construct( $fecha,$profundidad='i')
{
parent::__construct( $fecha );
$this->profundidad = $profundidad;
}
public function __toString() {
try
{
$now = new DateTime('now');
$diff = $this->diff($now); //ESTA ES LA LINEA QUE DA PROBLEMAS
foreach($this->strings as $key => $value){
if( (@$text .= ' '.$this->getDiffText($key, $diff)) ){
}
if($this->profundidad == $key) break;
}
return $text;
}
catch(Exception $e)
{
return '';
}
}
protected function getDiffText($intervalKey, $diff){
$pluralKey = 1;
$value = $diff->$intervalKey;
if($value > 0){
if($value < 2){
$pluralKey = 0;
}
return sprintf($this->strings[$intervalKey][$pluralKey], $value); }
return null;
}
}