dean7 Posted September 14, 2016 Share Posted September 14, 2016 (edited) Hey all I've got a simple problem of what I believe but its becoming a pain, I'm simply selecting a time from the database which is inputted in then I want to display it in Minutes and seconds; This is what I have. I should display the time I have left as I have got time left to wait although its always showing I'm free? Any reason behind this? Thanks for any help! if ($UsersTable1->action1time > time()){ $left = $UsersTable1->action1time - time(); $mins = floor($left / 60); // number of whole minutes left $secs = sprintf('%02d', $left % 60); // remainder of time left (in seconds) divided by 60. $Time = "$mins min and $secs secs"; }else{ $Time = "Free!"; } Edited September 14, 2016 by dean7 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted September 14, 2016 Share Posted September 14, 2016 So what is $UsersTable1->action1time? var_dump($UsersTable1->action1time); Quote Link to comment Share on other sites More sharing options...
dean7 Posted September 14, 2016 Author Share Posted September 14, 2016 So what is $UsersTable1->action1time? var_dump($UsersTable1->action1time); string(10) "1327751848" Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted September 14, 2016 Share Posted September 14, 2016 That date was back in 2012, so clearly it's not in the future. By the way, storing timestamps as integers is very bad practice. Not only is it very confusing (as you can see). It also makes date calculations a lot harder. Quote Link to comment Share on other sites More sharing options...
dean7 Posted September 14, 2016 Author Share Posted September 14, 2016 That date was back in 2012, so clearly it's not in the future. By the way, storing timestamps as integers is very bad practice. Not only is it very confusing (as you can see). It also makes date calculations a lot harder. Whats the best way todo this then? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted September 14, 2016 Share Posted September 14, 2016 MySQL Reference: Date and time types To store a timestamp (i. e. a date and a time), you use the DATETIME type. Quote Link to comment 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.