This question already has an answer here:
I want to subtract the datenow
and the registerdate
and use the result in a condition.
Following is the code:
public function actionCheckDate(){
date_default_timezone_set('Asia/Kuala_Lumpur');
$datenow = date('Y-m-d');
$id = Yii::app()->user->getState('id');
$models = GamesDevelopers::model()->find('id='.$id);
$registerdate = CHtml::encode($models->registerdate);
$active = strtotime($datenow)-strtotime($registerdate);
print_r($active);
die();
}
The result is : 627173 , how I gonna to know that 627173 is how many time or date ?
UPDATED
public function actionCheckDate(){
date_default_timezone_set('Asia/Kuala_Lumpur');
$datenow = date('Y-m-d H:i:s');
$id = Yii::app()->user->getState('id');
$models = GamesDevelopers::model()->find('id='.$id);
$registerdate = CHtml::encode($models->registerdate);
$diff = abs(strtotime($registerdate) - strtotime($datenow));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
printf("%d years, %d months, %d days
", $years, $months, $days);
die();
}
Worked fine but how to count hours ?
To find hours:
$hours = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)*24);
printf("%d hours
",$hours);
</div>