Jump to content

Calculate 2 time fields and update new field in database


simonq

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.