SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: Working out minutes from mysql
-
Jun 4, 2007, 17:31 #1
- 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);
thanks guys
Graham
-
Jun 4, 2007, 17:59 #2
- 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;
Studiotime - Time Management for Web Developers
to-do's, messages, invoicing, reporting - 30 day free trial!
Thomas Multimedia Web Development
-
Jun 4, 2007, 18:35 #3
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
Code:select ( unix_timestamp() -unix_timestamp(loggedindatetime) ) / 60 as minutes_logged_in from ...
-
Jun 5, 2007, 00:27 #4
- 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
cheers
Graham
-
Jun 5, 2007, 00:49 #5
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- 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.....
-
Jun 5, 2007, 00:50 #6
- 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.
-
Jun 5, 2007, 05:23 #7
- 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