What database field should this be?
I have a table called "Event". A column has "duration"--which is...how long that event lasts.
What database type should th开发者_运维问答is be? Integer? (in seconds)?
In the future, I will do statements such as:
If now() > event.duration THEN don't display the event.
In MySQL there is a column type called TIME
which can be used to store durations:
MySQL retrieves and displays TIME values in 'HH:MM:SS' format (or 'HHH:MM:SS' format for large hours values). TIME values may range from '-838:59:59' to '838:59:59'. The hours part may be so large because the TIME type can be used not only to represent a time of day (which must be less than 24 hours), but also elapsed time or a time interval between two events (which may be much greater than 24 hours, or even negative).
Note in particular that the limit is only 839 hours, so if you need more than that you might prefer to use an integer field instead.
If you want to fetch only events shorter than a certain duration you can do this with a WHERE clause. For example, to fetch only events that have lasted for less than 10 hours:
SELECT * From Event WHERE Duration < '10:00:00'
精彩评论