flemingmike Posted September 6, 2011 Share Posted September 6, 2011 hello, im trying to figure out the difference between 2 numbers in minutes. here is what i have: $tsignin="09-05 10:30:00"; $tsignina="09-06 11:30:00"; $log_in_time_stringsa = strtotime($tsignin); $log_out_time_stringsa = strtotime($tsignina); $difference_in_secondssa = ($log_out_time_stringsa - $log_in_time_stringsa); $tsigna = ($difference_in_secondssa / 60); $tsigna2 = number_format(round($tsigna)); the 09-05 is sept 5, and 09-06 is sept 6. this works if the month and date are not included. any ideas for me so i can figure out the total difference between date/times? Quote Link to comment Share on other sites More sharing options...
requinix Posted September 6, 2011 Share Posted September 6, 2011 To use strtotime() you must have a valid date string. "MM-DD HH:MM:SS" is not valid - what year is it? We know that you're talking about this year, but PHP doesn't know that. $tsignin = "2011-09-05 10:30:00"; Where are these date/times coming from? Why don't they have years? Quote Link to comment Share on other sites More sharing options...
flemingmike Posted September 6, 2011 Author Share Posted September 6, 2011 i was just taking a few different fields and making the timestamp. i have now made it include the year and it is almost working. it is giving me the difference in time, but not days. im getting a difference on 60minutes. is there a different way to do this so the whole timestamp gets subtracted? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 6, 2011 Share Posted September 6, 2011 Are these values coming from a DB query result? Quote Link to comment Share on other sites More sharing options...
requinix Posted September 6, 2011 Share Posted September 6, 2011 $tsignin="2011-09-05 10:30:00"; $tsignina="2011-09-06 11:30:00"; $log_in_time_stringsa = strtotime($tsignin); $log_out_time_stringsa = strtotime($tsignina); $difference_in_secondssa = ($log_out_time_stringsa - $log_in_time_stringsa); $tsigna = ($difference_in_secondssa / 60); $tsigna2 = number_format(round($tsigna)); echo "Logged in for {$tsigna2} minutes"; Logged in for 1,500 minutes Works for me... Quote Link to comment Share on other sites More sharing options...
flemingmike Posted September 6, 2011 Author Share Posted September 6, 2011 yes, coming from db query Quote Link to comment Share on other sites More sharing options...
flemingmike Posted September 6, 2011 Author Share Posted September 6, 2011 its working now. i think i didnt save my changes proper before testing. thanks for the help guys! 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.