Simple calculation problem...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

Simple calculation problem...

Post 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
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post 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";
?>
Post Reply