simonq Posted July 18, 2010 Share Posted July 18, 2010 Hi I need some help writing a php script to update my database. I have a table in mysql with these two fields "time_start" and "time_end". I created a new field call "time_total" and need to update this new field with the value calculated of "time_start" and "time_end". I need to take the "time_end" minus "time_start" and set the new value over to the "time_total" field. If anyone with a good knowledge of PHP can help please me write this update script. Thanks Link to comment https://forums.phpfreaks.com/topic/208069-calculate-2-time-fields-and-update-new-field-in-database/ Share on other sites More sharing options...
pernest Posted July 18, 2010 Share Posted July 18, 2010 Hello, The sql query you need is UPDATE table_name SET time_total = time_end-time_start you can wrap this up in the usual php mysql_query() function. You will need to be wary if any of your start and end times span 00:00:00, for example, a start time of 23:55:00 and an end time of 00:01:00 will give a weird negative time. If you have a full date time then I don't think that you will need to worry. Link to comment https://forums.phpfreaks.com/topic/208069-calculate-2-time-fields-and-update-new-field-in-database/#findComment-1087836 Share on other sites More sharing options...
simonq Posted July 18, 2010 Author Share Posted July 18, 2010 Thanks pernest! Link to comment https://forums.phpfreaks.com/topic/208069-calculate-2-time-fields-and-update-new-field-in-database/#findComment-1087905 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.