dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: Formating a time field using Avg

  1. #1
    Join Date
    Mar 2006
    Location
    Liverpool, UK
    Posts
    278

    Formating a time field using Avg

    Hi I am trying to get an average reading on a time field so say for instance I have two values

    00:00:02 and
    00:11:00

    I get the value 551 which is basically 1102 / 2 which is incorrect because the value I really want is 00:05:31. Has anyone got an idea how I can do this. Thanks in advance!

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    what dbms? what are the fields defined as in the db?

  3. #3
    Join Date
    Mar 2006
    Location
    Liverpool, UK
    Posts
    278
    Its a mysql database and the name of the field is completetime. Apoligies

  4. #4
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    i don't care about the name of the field, what type is it defined as?

    Assuming that it's defined as a TIME type, you probably want to use time_to_sec to convert the time type to a # of seconds and apply the average on that, then sec_to_time to convert the resulting seconds into a time format.

  5. #5
    Join Date
    Mar 2006
    Location
    Liverpool, UK
    Posts
    278
    Thanks for that! I did put that the field was a time field on my first line

    Hi I am trying to get an average reading on a time field so say for instance I have two values

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    Quote Originally Posted by cs3mw
    Thanks for that! I did put that the field was a time field on my first line
    But you'd be amazed how many times people have a field called "date" or "time" that is a char/varchar or integer field.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles