Location: PHPKode > scripts > Cool Date > coolDate.class.php
<?php

/*
 * Date Created: 11 Jan 2011
 * Create By: Gustavo Gontaruk
 * Please feel free to email me: hide@address.com
 *
 */

class Cool_Date {
  public $speech;

  function __construct( $dateTo, $dateFrom = 'now' ){
    $segundos = (strtotime($dateFrom)-strtotime($dateTo));	
	$minutos = abs((intval($segundos/60)));
	$horas = abs(intval($minutos/60));	
	$dias = abs(intval($horas/24));
	$meses = abs(intval($dias/30));
	$años = abs(intval($meses/12));	
	if($minutos == 0){			$this->speech = ("hace aprox. ".$segundos." segundos");
	}else if($minutos == 1){	$this->speech =  ("hace 1 minuto");
	}else if ($horas == 0){		$this->speech =  ("hace aprox. ".$minutos." minutos");
	}else if ($horas == 1){		$this->speech =  ("hace aprox. 1 hora");
	}else if ($dias == 0 && $horas < 24){
		if ($horas == 1){		$this->speech =  ("hace aprox. 1 hora");
		}else{					$this->speech =  ("hace " . $horas ." horas");
		}
	}else if ($dias == 1){		$this->speech = ("ayer");
	}else if ($dias <= 30){		$this->speech =  ("hace ". $dias ." dias.");
	}else if ($meses == 1){		$this->speech =  ("hace aprox. 1 mes");
	}else if ($meses < 12){		$this->speech =  ("hace ".$meses." meses");
	}else if ($años == 1){		$this->speech =  ("hace 1 año aprox");
	}else{						$this->speech =  ("hace ".$años." a&ntilde;os");
	}
  }

  public function getCoolDiffSpeech(){
    return $this->speech; 
  }

 
}

?>
Return current item: Cool Date