SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Working out minutes from mysql

    Hi Guys,

    i was wondering if anyone could tell me the correct way to work out how long a go (in minutes) a user logged in, i have this for the number of weeks ago since they joined:

    PHP Code:
         // Get the users details from mysql...//////////////////////////////////////////////
         
    $query_1 "SELECT id,username,login,user_class,about_me,country,avatar,join_date, FORMAT( DATEDIFF( NOW(),join_date)/7 ,0) AS join_date FROM `membership` WHERE `id`='$id'";
         
    $result_1 mysql_query($query_1) or die (mysql_error());
         
    $row mysql_fetch_array($result_1); 
    but i'm not sure how to do the next query for minutes since they logged in.

    thanks guys

    Graham

  2. #2
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the php method I would use is
    PHP Code:
    $start strtotime($start);
    $end strtotime($end);
    $duration = ($end $start) / 60
    not sure how to do in mysql, im sure someone in the mysql forums will know...
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,262
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Code:
    select ( unix_timestamp()
            -unix_timestamp(loggedindatetime) ) / 60
                      as minutes_logged_in
      from ...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys, it displays like so:

    PHP Code:
    6.7333 Minutes Ago 
    is there any way to cut off the decimal point?

    cheers

    Graham

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    morning Graham, have a look at number_format()

    edit

    actually ignore number format and just use round();
    PHP Code:
    round(6.7333); 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to cut off the decimal point entirely.. you have a few options.

    Do you want to round up or down?

    If you want to round down: floor() is the function
    If you want to round up: ceil() is the function

    If you just want to chop off the decimal..

    [/php]
    $variable = 6.7893;
    <?php
    list($int, $dec) = explode(".", $variable);

    echo $int;
    ?>
    [/php]

    This would give you 6 in the int variable, and 7893 in the dec variable. Hope that helps.

  7. #7
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That does indeed help thanks for that guys, iv learned a new function today aswell

    thanks again

    Graham


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
  •