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

  • SEARCH
  • Home
  • 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 4125904
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:55:50+00:00 2026-05-20T23:55:50+00:00

So, I want to run a quick query to give me some information on

  • 0

So,
I want to run a quick query to give me some information on times taken to send messages.

my plan is

  1. count how many messages we are sending
  2. work out the difference between the max and the min datetime for the messages
  3. work out how much time it took per message.

So my query ended up being

SELECT 
COUNT(id)                                                          AS message_sent,
TIMEDIFF(MAX(msg_sent_datetime), MIN(msg_sent_datetime))           AS total_time_taken,
COUNT(id)/TIMEDIFF(MAX(msg_sent_datetime), MIN(msg_sent_datetime)) AS time_per_message
FROM sent_txts_none_action_child 
GROUP BY parent_id;

The first two sections work fine.
You run into trouble with number three.

Example output.

message_sent|total_time_taken|time_per_message
5           |00:00:01        |5.0000000000
5           |00:00:00        |NULL
5           |00:00:01        |5.0000000000
7647        |00:28:12        |2.7194167852

What is the third column outputting?
What do I need to change to get it to output the correct value?


Edit

ok so after making the suggested change in the comment I get

message_sent|total_time_taken|time_per_message
5           |00:00:01        |0.2000000000
5           |00:00:00        |0.0000000000
5           |00:00:01        |0.2000000000
7647        |00:28:12        |0.3677259056

which still is not what we want.
as if you times 0.3677259056 by 7647 you get 2812.

So whats the issue?
MYSQL is not converting the datediff value to anything logical,

instead it is treating it as a simple number and ignoring any non numeric characters…

Why does mysql not convert this to seconds/milliseconds?

Is there a function I can use to do this?

  • 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-05-20T23:55:50+00:00Added an answer on May 20, 2026 at 11:55 pm

    http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timediff

    TIMEDIFF() returns a time value. However, when you perform any numeric maths on it, it turns into a numeric value that is useless (just mashing the digits from the time in textual form).

    work out how much time it took per message.

    So you really mean, time / message-count. The divisor should be the count.

    What you got is the inverse, which is messages that could be sent per unit time, which is seconds. In other words, what you calculated is how many messages could be sent per second, on average.

    SELECT 
    COUNT(id)                                                          AS message_sent,
    TIMEDIFF(MAX(msg_sent_datetime), MIN(msg_sent_datetime))           AS total_time_taken,
    TIME_TO_SEC(TIMEDIFF(MAX(msg_sent_datetime), MIN(msg_sent_datetime)))/COUNT(id) AS time_per_message
    FROM sent_txts_none_action_child 
    GROUP BY parent_id;
    

    The resultant time_per_message column is measured in seconds.

    Reference: TIME_TO_SEC()

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

Sidebar

Related Questions

I want to run an update query. The query will be run against multiple
I want to run some Find statements that only show results from the current
I want to run a query which grabs all courses . Each row (course)
I'm trying to run a very quick update query to record that a user's
I want run all script from the directory . Like , The directory contains
I want run a script as follows: runner: ssh 'java program &' ssh 'java
Why this code don't work,when i want run this code vwd 2008 express show
I have written php program and uploaded on server. I want run this program
Want to run javascript function from parent window in child window Example I have
I want to run code which needs boost libraries. I built it using CMake.

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.