Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:33:43+00:00 2026-06-15T01:33:43+00:00

I created a field called ‘hours_spent’ in MySQL using the decimal datatype to store

  • 0

I created a field called ‘hours_spent’ in MySQL using the decimal datatype to store time. The values are stored like this 1.30, 2.30 etc… (for 1hr30min, 2hr30min).

I want to calculate the sum of various time values.

The sum of time is not what I expected: 1.30 + 2.30 = 3.60, whereas I expected 4.00.

I used the SUM function in MySQL to count the hours_spent field. If the values are 0.30 + 1.50 = 1.80, whereas I expected 2.20.

My first mistake was to use the decimal type instead of the time datatype, but I cannot change datatype.

So, is there any way to sum the time values and get result as I expect?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:33:44+00:00Added an answer on June 15, 2026 at 1:33 am

    I prepared you a demo at sqlfiddle, you can try it there if you want:

    http://www.sqlfiddle.com/#!2/c9afc/2

    Here are the query samples:

    select @indexer:=instr(dateasdecimal, '.')
    , left(dateasdecimal, @indexer-1) * 60 + substr(dateasdecimal, @indexer+1)  as totalMinutes
    from testtable;
    
    select @indexer:=instr(dateasdecimal, '.')
    , sum(left(dateasdecimal, @indexer-1) * 60 + substr(dateasdecimal, @indexer+1))  as totalMinutes
    from testtable;
    

    Note: Please don’t forget to accept answers to your questions:
    https://meta.stackexchange.com/a/65088/200585

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using rails 2.3.4 When I execute rake db:test:prepare the id field created is
I created an image field in a vocabulary called field_category_image. It does not show
I have a MySQL database table C with a field called Phone . I've
I have created a custom metadata field called Record Date to my videos, and
I have a query in CakePHPthat has a stored datetime field called DropIn.drop_in_time .
I've a table with a datetime (format: 'Y-m-d H:i:s') 'created' field and 'amount' (integer)
My site is deployed on heroku. Time.now will return today, but the created_at field
I've created a custom field type in Joomla and need to pass parameters to
I have a 'created_date' DATETIME field which I would like to be populated with
I have created an on the fly search field in Java Swing. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.