Page 1 of 1

Simple calculation problem...

Posted: Wed Sep 11, 2002 5:52 am
by 9902468
This has bugged me for a while now.. i'm trying to calculate how many days have passed since unix epoch, but failed so far... I have tried like this:

floor($unix_timestamp / 86400);
intval($unix_timestamp / 86400);

but Im not getting the right values all the time, most of the time yes, but not all the time. The unix time stamp can be any given time since epoch. Are there any other ways to calculate this. (Or functions that I'm unaware of?)

thanks

-9902468

Posted: Wed Sep 11, 2002 11:22 am
by dusty
whats the timestamp look like?

floor(time()/86400);

should work fine..and since i accidently misread your post :roll: here it is broken down into years days hours minutes and seconds.

Code: Select all

<?
$years = floor(time()/31536000);
$days = (time()/86400) % 365;
$hours = (time()/3600) % 24;
$minutes = (time()/60) % 60;
$seconds = time() % 60;
echo "$years years, $days days, $hours hours, $minutes minutes, $seconds seconds";
?>