If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Soring time in DB

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-23-07, 12:01
nicpon nicpon is offline
Registered User
 
Join Date: Jan 2005
Posts: 48
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?
Reply With Quote
  #2 (permalink)  
Old 02-23-07, 13:05
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
store it as TIME
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-23-07, 13:33
nicpon nicpon is offline
Registered User
 
Join Date: Jan 2005
Posts: 48
How about fractions of a second ?
Reply With Quote
  #4 (permalink)  
Old 02-23-07, 14:13
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
ah

well, in that case, use DECIMAL(9,2) or whatever precision you need, to store seconds
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 02-23-07, 14:55
nicpon nicpon is offline
Registered User
 
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?
Reply With Quote
  #6 (permalink)  
Old 02-23-07, 21:47
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 02-23-07, 23:35
nicpon nicpon is offline
Registered User
 
Join Date: Jan 2005
Posts: 48
I will look around and see what I find.
Thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On