[dba-SQLServer] What datatype to use for a Time field

Arthur Fuller fuller.artful at gmail.com
Mon Oct 8 08:22:09 CDT 2007


1. This is always a tough one conceptually, IME. I have wrestled with this
one a dozen times at least. I have finally concluded that a moment in time
implies a date and that either the database or the front end ought to supply
said date. Noon on Monday is not the same as Noon on Tuesday, except in
terms of presentation, and Noon on no date is a meaningless concept.

This may seem an academic distinction to some readers, but I don't see any
viable alternatives. Your FE may just request an abstract time, such as
preferred lunch hour. In such a case I wouldn't use a datetime data type. In
fact, I just had one of these crop up, and fortunately the requirement was
"on the hour" -- so I created a lookup table called Hours and populated it
with two columns and 24 records, the first column being autonumber (1...24,
conveniently corresponding to military time), the second column being "1 PM"
etc.

Either you want a real representation of date/time or you want an abstract
concept called Time. These two things are IMO quite different. Just my $.02
on this subject.

2. Drag the right edge of the column header out as far as you wish.

hth,
Arthur

On 10/8/07, pcs at azizaz.com <pcs at azizaz.com> wrote:
>
> Hi,
>
> What datatype to use when creating a field / column to
> handle handle time - say in 24 hour format -
> If I use DateTime datatype - when entering 10:00; 14:00 or
> 2:00 PM the system enters current date and the time - I just
> want the time part!
>
> In Access you could easily format the field to display the
> time element only.
> And if removing the Format element on the field - it still
> only displays the time element.
>
> What's 'best practice' is SQL?  (using SQL2005)
>
> Another question:
> How to widen the last column in a view in SSMS ??
>
> Regards
> Borge
> _______________________________________________
> dba-SQLServer mailing list
> dba-SQLServer at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
> http://www.databaseadvisors.com
>
>



More information about the dba-SQLServer mailing list