Just the time...

Hi,

I'm new to SQLServer and I would like to know how I store times without dates!

I simply want to store a duration which has no concept of a date, but I cannot seem to find a data type that does the job.

Am I missing something obvious

Cheers,

Roy


Answer this question

Just the time...

  • RickLa

    Datetime is the only "temporal" format in SQL Server (that you can then use with Datediff, Datepart, etc).

    What you may want to consider, since you're storing a duration, is to use something like an int field, and store the duration as a matter of units. 

    For example, if your base unit is seconds, and you have a duration of 2 hours, 16 minutes, 32 seconds, then store:  2*3600 + 16*60 + 32 = 8192 seconds.

    btw--those are just random numbers out of my head, but how neat that it came out to be 8K exactly!

    Or, you could always just store the time as a string (varchar).


  • -=B3N=-

    Seems reasonable, efficient and obvious! I don't need to store anything less than seconds so this will do nicely.

    Cheers,

    Roy

  • Just the time...