[eluser]mddd[/eluser]
Robert,
Everybody has their own ways of doing things and that's okay
I like to use the data types in myqsl as much as I can. So if I store a time, I would use a datetime field or just a time field.
My guess is you are storing something like opening hours for a company? I would make a table something like
Code:
id (int) database id you can use for writing, deleting etc
company_id (int) the company id
day_id (int) the number of the day
opening (time) the time of opening
closing (time) the time of closing
Now if you need the times for the whole week for company number 1 you would say
Code:
SELECT * FROM opening_hours WHERE company_id=1
Or if you only want the hours for wednesday you could say
Code:
SELECT * FROM opening_hours WHERE company_id=1 AND day_id=3
Or if you want to know which companies are still open at 6PM on a friday
Code:
SELECT company_id FROM opening_hours WHERE day_id=5 AND opening<'18:00:00' AND closing>'18:00:00'
See.. very flexible.
Oh, one more reason why it is good to use these field types: you can easily get things formatted the way you want, using the functions in MySql. No need to write any php code to figure out the parts and so on.
Eg, if you want your opening time to look like '7:00AM', use TIME_FORMAT(opening, '%k %p').
If you want it to look like '07:00:00', use TIME_FORMAT(opening, '%H:%i:%s').
Easy.