Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2005
    Posts
    48

    Unanswered: Soring time in DB

    Hey,
    I'm creating a sports time record book and I'm wondering what is the best way to store time in database. The times I have look like that 1:45.00(1 minute 45 sec and 00/100) or 0:30.50(30sec+50/100). I know I could store it as text, but I would like it to be more robust as far as displaying and sorting goes.
    DO you have any suggestions?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    store it as TIME
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2005
    Posts
    48
    How about fractions of a second ?

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    ah

    well, in that case, use DECIMAL(9,2) or whatever precision you need, to store seconds
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jan 2005
    Posts
    48
    that still doesn't solve my problem because if I use decimal then I have convert everything to seconds or some other common denominator and that is going to be a pain. There has to better way to handle that. I would rather store fractions in other table then do some kind of conversions... How does that sounds?

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    i would do the conversion

    you've heard of the TIME_TO_SEC and SEC_TO_TIME functions?

    you can use a single DECIMAL column, and handle the decimal (fraction of second) separately in the calculation
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Jan 2005
    Posts
    48
    I will look around and see what I find.
    Thanks

Posting Permissions

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