lalnfl Posted September 23, 2010 Share Posted September 23, 2010 How would you get ten minutes ago from the current time? Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/ Share on other sites More sharing options...
kenrbnsn Posted September 23, 2010 Share Posted September 23, 2010 I would use strtotime <?php $ten_minutes_ago = strtotime('-10 minutes'); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1114369 Share on other sites More sharing options...
lalnfl Posted September 24, 2010 Author Share Posted September 24, 2010 It doesn't seem to work when I do this. $time = time() - $ten_minutes_ago; it just shows 600 when I echo it Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115315 Share on other sites More sharing options...
milesap Posted September 24, 2010 Share Posted September 24, 2010 It doesn't seem to work when I do this. $time = time() - $ten_minutes_ago; it just shows 600 when I echo it Ahaha 600 seconds is 10 mins . . . Just divide 600 by 60 to display it in minutes. Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115317 Share on other sites More sharing options...
lalnfl Posted September 25, 2010 Author Share Posted September 25, 2010 I know that it was displaying seconds. My problem is that I want it to subtract it from the current time. How would you do that? Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115352 Share on other sites More sharing options...
kenrbnsn Posted September 25, 2010 Share Posted September 25, 2010 In my example, the variable $ten_minutes_ago is the time in seconds of ten minutes ago. You don't have to subtract it from anything. If you do you will get 600. Ken Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115359 Share on other sites More sharing options...
lalnfl Posted September 25, 2010 Author Share Posted September 25, 2010 Oh so the strotime already subtracts 10 minutes from the current time? Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115367 Share on other sites More sharing options...
kenrbnsn Posted September 25, 2010 Share Posted September 25, 2010 The strtotime function can do a lot of things with the time. I suggest you read the manual page. Another way of getting the time 10 minutes ago is: <?php $ten_minutes_ago = time() - 600; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115373 Share on other sites More sharing options...
jcbones Posted September 25, 2010 Share Posted September 25, 2010 echo date('m/d/Y h:i:s A',strtotime('-10 minutes')); Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115400 Share on other sites More sharing options...
lalnfl Posted September 25, 2010 Author Share Posted September 25, 2010 Okay I have another question. Why isn't this SQL query working??? $sql_members_online = mysql_query("SELECT last_login_date FROM Member WHERE last_login_date BETWEEN '$time' AND '$current_time'"); the $time is the time with 10 minutes subtracting from the current time and there is a last_login_date with datetime field, its just called last_login_date Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115405 Share on other sites More sharing options...
jcbones Posted September 25, 2010 Share Posted September 25, 2010 echo the query to make sure the variables are defined as you think they should be. This is one reason to set the query in it's own variable. $sql = "SELECT last_login_date FROM Member WHERE last_login_date BETWEEN '$time' AND '$current_time'"; $sql_members_online = mysql_query($sql) or die('Error: ' . $sql . '<br />' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115408 Share on other sites More sharing options...
lalnfl Posted September 25, 2010 Author Share Posted September 25, 2010 They are and I am still getting 0 as a result when I use mysql_num_rows. Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115409 Share on other sites More sharing options...
kenrbnsn Posted September 25, 2010 Share Posted September 25, 2010 What are the formats of the different fields? DATE, DATETIME, or UNIXTIME? Ken Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115410 Share on other sites More sharing options...
lalnfl Posted September 25, 2010 Author Share Posted September 25, 2010 last_login_date is DATETIME and I assume $time and $current_time is UNIXTIME Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115411 Share on other sites More sharing options...
jcbones Posted September 25, 2010 Share Posted September 25, 2010 So you are checking an actual date, against seconds? And, it doesn't work? Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115412 Share on other sites More sharing options...
lalnfl Posted September 25, 2010 Author Share Posted September 25, 2010 I am checking to see if last_login_date is between the Current Time and the time 10 Minutes ago. Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115414 Share on other sites More sharing options...
lalnfl Posted September 25, 2010 Author Share Posted September 25, 2010 Anyone know what I am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115551 Share on other sites More sharing options...
lalnfl Posted September 25, 2010 Author Share Posted September 25, 2010 Bump Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115571 Share on other sites More sharing options...
Pikachu2000 Posted September 25, 2010 Share Posted September 25, 2010 As long as your data type is DATETIME, see my response in this thread. It should give you a good idea of how to approach this. Quote Link to comment https://forums.phpfreaks.com/topic/214163-help-with-time/#findComment-1115616 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.