Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Timestamps

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Timestamps

    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!
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    divide it by 3600 ?

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

    like

    PHP Code:
    $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 ){
           
    $rest1 = ($rest 3600);
           
    $hours = ($rest $rest1) / 3600;
           if( 
    $rest1 60 ) {
               
    $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

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •