I have a situation where I want users to be able to specify a time range, where the time is a relative range that exist in a given week. So a user could pick Monday 5PM – Tuesday 1AM. Think of it kind of like “what time is a person’s work shift”.
My first reaction is that I could store “relative” times. So assuming the week starts on Monday at 00:00:00, Monday at noon would be indicated as 86400/2=43200. I don’t really like this method, because it makes handling time-zones a bit difficult.
Is there a “best” way for doing this (or just a good one)? Does MySQL have some sort of data type that deals with this specifically?
I’ve tagged this “Perl” and “MySQL”, since I will be using them for this application, but the answer doesn’t have to be specific to either of them technically.
The best answer will depend somewhat on what you will do with the data downstream.
But I would recommend avoiding any hacks and doing a straightforward approach (table syntax Sybase, since my MySQL is rusty – sorry)
An alternate approach is to store the offset ( in seconds ) from Sunday 00:00, both start and end offset. This offers its benefits (e.g. range comparisons are merely
<and>operators instead of complex expressions).