cheechm Posted September 18, 2008 Share Posted September 18, 2008 How would I add one hour to the time and echo it in the following format: date("H:i:s") Thanks Quote Link to comment https://forums.phpfreaks.com/topic/124860-time/ Share on other sites More sharing options...
.josh Posted September 18, 2008 Share Posted September 18, 2008 time Quote Link to comment https://forums.phpfreaks.com/topic/124860-time/#findComment-645053 Share on other sites More sharing options...
akitchin Posted September 18, 2008 Share Posted September 18, 2008 $timestamp_plushour = time() + 3600; $formatted_date = date('H:i:s', $timestamp_plushour); echo $formatted_date; there are a zillion ways to skin the cat when it comes to dates and times; this is but one of them. EDIT: CV's brief post has beaten me to the punch - thine fingers are brisk, CV. Quote Link to comment https://forums.phpfreaks.com/topic/124860-time/#findComment-645054 Share on other sites More sharing options...
cheechm Posted September 18, 2008 Author Share Posted September 18, 2008 Thanks, so I have this in my database: time_visited = 21:00:00 How would I compare the current time using $time = time() + 3600; $expire_time = date('H:i:s', $time); to time_visited? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/124860-time/#findComment-645057 Share on other sites More sharing options...
.josh Posted September 18, 2008 Share Posted September 18, 2008 EDIT: CV's brief post has beaten me to the punch - thine fingers are brisk, CV. haha nope, just shorter post. Quote Link to comment https://forums.phpfreaks.com/topic/124860-time/#findComment-645058 Share on other sites More sharing options...
akitchin Posted September 18, 2008 Share Posted September 18, 2008 Thanks, so I have this in my database: time_visited = 21:00:00 How would I compare the current time using $time = time() + 3600; $expire_time = date('H:i:s', $time); to time_visited? Thanks that only works for UNIX timestamps, which time() generates. if your time is in the database in TIME format, you can simply use: DATE_ADD(time_visited, INTERVAL 1 HOUR) in MySQL itself. Quote Link to comment https://forums.phpfreaks.com/topic/124860-time/#findComment-645070 Share on other sites More sharing options...
cheechm Posted September 18, 2008 Author Share Posted September 18, 2008 Doesn't work.. Hmmm.... $time = time() + 3600; $expire_time = date('H:i:s', $time); $sql = "SELECT username FROM login WHERE DATE_ADD(last_visit_time, INTERVAL 1 HOUR) < $expire_time" or die(mysql_error ()); $result = db_query($sql); $users_online = array(); while ($row = db_fetch_array($result)) { echo $row['username']; } Thanks Quote Link to comment https://forums.phpfreaks.com/topic/124860-time/#findComment-645083 Share on other sites More sharing options...
The Little Guy Posted September 18, 2008 Share Posted September 18, 2008 echo date("H:i:s",strtotime("now + 1 hour")); Quote Link to comment https://forums.phpfreaks.com/topic/124860-time/#findComment-645085 Share on other sites More sharing options...
akitchin Posted September 18, 2008 Share Posted September 18, 2008 what field type is the last_visit_time field? Quote Link to comment https://forums.phpfreaks.com/topic/124860-time/#findComment-645086 Share on other sites More sharing options...
cheechm Posted September 18, 2008 Author Share Posted September 18, 2008 last_visit_time is type "time" Quote Link to comment https://forums.phpfreaks.com/topic/124860-time/#findComment-645207 Share on other sites More sharing options...
akitchin Posted September 19, 2008 Share Posted September 19, 2008 you were performing the calculation on the incorrect field: SELECT username FROM login WHERE last_visit_time < TIME(NOW() + INTERVAL 1 HOUR) it needed to change slightly since you're using the time fieldtype. Quote Link to comment https://forums.phpfreaks.com/topic/124860-time/#findComment-645598 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.