Jump to content

[SOLVED] Calculating SUM time beyond MySQL TIME field limit ?!


Recommended Posts

Hi

 

I`m creating a flight logbook for myself where I add flight details including flight start and end as DATETIME fields then add the block time in a TIME field.

 

I know how to do the SUM by using this snippet:

SELECT
SEC_TO_TIME( SUM( TIME_TO_SEC( `block` ) ) ) AS total_time 
FROM t1

 

Yet as a pilot I will accumulate a total flying time more than the limit of the TIME field limits which is according to the MySQL document is 838:59:59 , the total flying hours can run into 10000:00:00 hours and more.

 

Now here is my question , How do I create the correct statment to give the correct total and not run into the limit , shall I change the field type from TIME to something else ?

 

Thanks for any suggestions.

 

try this pretty heavy but should work  :P

 


SELECT concat(floor(SUM( TIME_TO_SEC( `block` ))/3600),":",floor(SUM( TIME_TO_SEC( `block` ))/60)%60,":",SUM( TIME_TO_SEC( `block` ))%60) AS total_time 
FROM t1

Thanks rajivgonsalves for the reply , its quite heavy solution.

 

try this pretty heavy but should work  :P

 


SELECT concat(floor(SUM( TIME_TO_SEC( `block` ))/3600),":",floor(SUM( TIME_TO_SEC( `block` ))/60)%60,":",SUM( TIME_TO_SEC( `block` ))%60) AS total_time 
FROM t1

 

fenway yes I think thats what I should do , make the field as INT type and store the block as minutes and then reformat the output using php , I think thats the only soultion.

 

Thank you all for trying and help.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.