SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Convert "1350" to hours?

    I've been messing around with timestamps for a while and I'm having difficulty knowing how to do this because there are so many options with timestamps.

    My question is, how can i convert the last result into hours? (Just scroll to the bottom)
    Im comparing times and trying to get the hours here by the way.

    Code MySQL:
    SELECT 
        UNIX_TIMESTAMP(stamina_timer) AS stamina_timer 
    FROM 
        users 
    WHERE 
        id = 0
    LIMIT 1

    PHP Code:
    echo $stamina_timer;
    echo 
    $now time(); 
    Result:
    Code:
    stamina_timer:     1255889442
    now:             1255890667
    PHP Code:
    $now $stamina_timer
    Result:
    Code:
    1350
    How do I convert 1350 into whatever time it is?

  2. #2
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't there 60 seconds in a minute, and the 60 minutes in an hour?

  3. #3
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  4. #4
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just wanted to know how many hours passed not the 12 hour time

  5. #5
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This look like it works:

    PHP Code:

        $total 
    $time_1 $time_2;

        
    $time = array();
        
        
    $time['minutes']    =    floor($total 60);
        
    $time['hours']        =    floor($time['minutes'] / 60);
        
    $time['days']        =    floor($time['hours'] / 24);
        
    $time['months']        =    floor($time['days'] / 30);
        
    $time['years']        =    floor($time['months'] / 12); 

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,247
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    if stamina_timer is a DATETIME or TIMESTAMP column, you can also do this --

    SELECT DATEDIFF(stamina_timer,CURRENT_TIMESTAMP) AS time_difference

    and save yourself the php calculation
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    if stamina_timer is a DATETIME or TIMESTAMP column, you can also do this --

    SELECT DATEDIFF(stamina_timer,CURRENT_TIMESTAMP) AS time_difference

    and save yourself the php calculation
    WOW that is an amazing things TY


Bookmarks

Posting Permissions

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