hasamba Posted March 4, 2011 Share Posted March 4, 2011 Hi all. I'm a newbie to PHP and Mysql, and I hope you can help me. I have a table called "jos_log", in that table I have a column called "total" which stores total time like this 14:00. I need a PHP script that can sum that time column and display it in a text box called "total_time". Looking forward to hear from someone Cheers. Hasamba Quote Link to comment https://forums.phpfreaks.com/topic/229622-sum-total-time-column-with-php/ Share on other sites More sharing options...
The Little Guy Posted March 4, 2011 Share Posted March 4, 2011 you should really store the date in the database as a timestamp, which would be formatted like so: YYYY-MM-DD HH:MM:SS eg. 2001-03-09 22:46:30 That would make it much easier to calculate times. Quote Link to comment https://forums.phpfreaks.com/topic/229622-sum-total-time-column-with-php/#findComment-1183062 Share on other sites More sharing options...
Muddy_Funster Posted March 5, 2011 Share Posted March 5, 2011 If you're looking for a PHP script, wouldn't it have made more sense to post in the PHP Help section instead ? What field type is total just now? and what type of duration are you reffering to by 14:00? hours or minutes? Quote Link to comment https://forums.phpfreaks.com/topic/229622-sum-total-time-column-with-php/#findComment-1183078 Share on other sites More sharing options...
hasamba Posted March 5, 2011 Author Share Posted March 5, 2011 Hi, The total field is also TIME. I already have a PHP script that calculate startTime and endTime and gives me the Total for each row. Now I need a PHP script that will automatic SUM the column Total in DB and will represented the SUM in a text field. The format should be HH:mm. One thing I forgot to mansion! I'm doing this to save my Filght Time (I'm a Pilot). Which means, The SUM time is a lot higher the 24:00. Right now I have 60:00 hours. Do you think I should move it to the PHP section? Quote Link to comment https://forums.phpfreaks.com/topic/229622-sum-total-time-column-with-php/#findComment-1183178 Share on other sites More sharing options...
Pikachu2000 Posted March 5, 2011 Share Posted March 5, 2011 No need to post in more than one forum, as it violates the forum rules and TOS. You can do this in the query without a problem. SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(`total_time`))) FROM `table` WHERE . . . Quote Link to comment https://forums.phpfreaks.com/topic/229622-sum-total-time-column-with-php/#findComment-1183231 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.