Friday, March 9, 2012

Save a time value in a column

Hi all!
What is the best way to save a time value (not the date) in a column
of a SQL Server 2005 database?
Thanks in adavance.
--
Marco Minerva, marco.minerva@.gmail.com
http://blogs.ugidotnet.org/marcomHi
CREATE TABLE #t (t CHAR(8))
INSERT INTO #t SELECT CONVERT(CHAR(10),GETDATE(),108)
SELECT * FROM #t
<marco.minerva@.gmail.com> wrote in message
news:1193742138.605341.4690@.k79g2000hse.googlegroups.com...
> Hi all!
> What is the best way to save a time value (not the date) in a column
> of a SQL Server 2005 database?
> Thanks in adavance.
> --
> Marco Minerva, marco.minerva@.gmail.com
> http://blogs.ugidotnet.org/marcom
>|||On Tue, 30 Oct 2007 04:02:18 -0700, marco.minerva@.gmail.com wrote:
>Hi all!
>What is the best way to save a time value (not the date) in a column
>of a SQL Server 2005 database?
>Thanks in adavance.
SQL Server 2008 is to have a time datatype, but that doesn't help you
now. Today there are no good ways, just a variety of ways with
shortcomings.
Use a datetime with a specific date (1 January 1900 for example) that
has to be ignored by the application.
Use a number and store the number of milliseconds (or seconds, as
required) from midnight and convert as required.
Use a string.
I would tend toward the datetime with a constraint on the date, PLUS a
derived column that returns the time as a string using CONVERT with
style 114: CONVERT(char(12),colname,114).
Roy Harvey
Beacon Falls, CT|||On 30 Ott, 12:30, "Roy Harvey (SQL Server MVP)" <roy_har...@.snet.net>
wrote:
> On Tue, 30 Oct 2007 04:02:18 -0700, marco.mine...@.gmail.com wrote:
> >Hi all!
> >What is the best way to save a time value (not the date) in a column
> >of a SQL Server 2005 database?
> >Thanks in adavance.
> SQL Server 2008 is to have a time datatype, but that doesn't help you
> now. Today there are no good ways, just a variety of ways with
> shortcomings.
> Use a datetime with a specific date (1 January 1900 for example) that
> has to be ignored by the application.
> Use a number and store the number of milliseconds (or seconds, as
> required) from midnight and convert as required.
> Use a string.
> I would tend toward the datetime with a constraint on the date, PLUS a
> derived column that returns the time as a string using CONVERT with
> style 114: CONVERT(char(12),colname,114).
> Roy Harvey
> Beacon Falls, CT
Thanks to all!
--
Marco Minerva, marco.minerva@.gmail.com
http://blogs.ugidotnet.org/marcom

No comments:

Post a Comment