I am writing an app that allows people to schedule things for certain times and then displays them. The time of the event is stored in the database as an SQL TIME, because there are things I’m doing in the DB that need this structure.
However, on the output page I want the time to be in 12:00 am/pm format, but I don’t want to run a conversion script every time I step through the database output loop. I don’t want this:
while (database loop){ convert to clean time output event info, with clean time }
because I think it is too much strain and unneccesary. Is there a way to do this better short of storing the time in the db twice (once in 24 hour and once in 12)?
The output page is your presentation layer. Don’t mix up presentation issues into the database layer. Especially don’t force a denormalisation just for presentation’s sake.
Whyever not? Depending on what language you’re using it shouldn’t be any more work than just sending the time through a strftime() operation before plonking it onto the page. It’s not going to be slow.