Skip to main content
Participating Frequently
March 10, 2010
Question

Should my app store durations in seconds?

  • March 10, 2010
  • 2 replies
  • 1082 views

I'm building an application that keeps track of events.  It makes more sense to store one date, which is when the event begins, and the duration of that event.  Now, events will never need to be tracked down to the second, but for some reason I have this itching feeling that it should store the duration of these events in seconds in the DB as INT fields, as opposed to storing the minutes.

Is my gut telling me a good thing to go for seconds?  Or should I be realistic and go with minutes because that's all my application needs?  I'd love to hear some different opinions on this.

Thanks,

Adam Bellas

    This topic has been closed for replies.

    2 replies

    Inspiring
    March 12, 2010

    The strategy of using two time-stamp values always wins for me.  Even if I have to reschedule an event or change its ending time, I'm still able to do it using known-good date/time manipulation routines ... whether in the SQL queries or in ColdFusion code.  I can easily calculate the difference between the two, in whatever level-of-detail I may need, just by asking for it.  Everything throughout the entire system, in both the app and the database servers, knows that these are "two precisely defined 'points in time.'"  There is no "tricky, unexplainable math" out there, just waiting to get munged-up by a smple, easily overlooked typo (like the one in this very sentence) in one isolated query or expression among many dozens.

    VurceaseAuthor
    Participating Frequently
    March 12, 2010

    Agreed.  A large element of my decision to ultimately go with dates here is that I won't need to go explain the time + duration system to every developer who needs to work on it.  It's just not a common system.  Plus all the other excellent points about systems knowing how to effectively deal wtih dates makes a ton of sense, too.

    Owainnorth
    Inspiring
    March 11, 2010

    How about storing them both as dates - the start date and the end date. All database engines deal with dates pretty efficiently, so there's no real disadvantage.

    That way your interval calculation is all done at displaytime, and you can change that as and when you feel like it.

    O.

    Inspiring
    March 11, 2010

    Just to add a mostly pointless "me too" to this post: when storing event data, I always store start and finish times, not start time and duration.

    --

    Adam