using Time on a SQL server database?

  • can anyone help me please, I need to set up a field on my database to store hours and minutes with the view of being able to do calculations on that field, what is the best way? just store minutes and convert back to hours and minutes afterwards in the stored procedure , or store as hours and minutes?

    I'm using this as an Annual Leave database and need to be able to store the amount of hours each person has for his or her leave and have the ability to subtract the amount of time in hours and minutes that each person takes. I've tried creating a datetime field to store the time in it, the first problem I've found is I can't store 200 hours and 20 minutes

  • My opinion would be to store minutes and do the conversion on the way out.

     

    store 2 hours 15 minutes as 135

     

    Hope this helps

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Thanks Jason, I more or less made my mind up to do just that. I couldn't see any easier way of doing it

  • Try the link below for guidelines to SQL Server DateTime data type use and known issues and limitations.  Hope this helps.

    http://www.karaszi.com/SQLServer/info_datetime.asp

    Kind regards,

    Gift Peddie

    Kind regards,
    Gift Peddie

  • many thanks for the info

  • The datetime type is designed to store a point in time - it is not designed to necessarily store a duration unless you base that duration from time dot

    Definitely store your duration in minutes - convert to hours & mins in the application that displays the data.  This way you avoid the need to wrap at 60min boundaries, etc.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply