...

View Full Version : Timestamps



ACJavascript
01-24-2004, 11:03 PM
Hello all,

okay heres my problem,

I have a time stamp

for an example: 86400 (24 hours)

NOW - How can I take that timestamp and turn it into 24 hours OR 1 day? how can I do that?


Any help is MUCH appreciated!

raf
01-24-2004, 11:42 PM
divide it by 3600 ?

I'm not sure what you want. Do you mean something like x days, y hours etc

like



$diff = $timestamp; //$timestamp is your timestamp value
$seconds = 0;
$hours = 0;
$minutes = 0;

if($diff % 86400 > 0) {
$rest = ($diff % 86400);
$days = ($diff - $rest) / 86400;
if( $rest % 3600 > 0 ){
$rest1 = ($rest % 3600);
$hours = ($rest - $rest1) / 3600;
if( $rest1 % 60 > 0 ) {
$rest2 = ($rest1 % 60);
$minutes = ($rest1 - $rest2) / 60;
$seconds = $rest2;
} else {
$minutes = $rest1 / 60;
}
} else {
$hours = $rest / 3600;
}
}else
$days = $diff / 86400;
}

Stolen from nobody at
http://www.php.net/manual/en/function.time.php
and slightly adapted

ACJavascript
01-24-2004, 11:54 PM
Hey thanks alot raf!

I originaly went to PHP.net but couldn't figure out the time function to get exactly what I wanted.

But you hit it right on the nail!

Thanks again

raf
01-25-2004, 12:03 AM
You're welcome.

php.net usually has a user contribution for all these sort of functions where you think 'there must be lots of people that sometimes have to do this !' so i always read all usercomment on my daily visits overthere to see if i can save myself some time in the future. and then it's just a matter of having a keyword-sensitive-memory or trying a few relevant keywords...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum