Monday, March 19, 2012

Current Date in Default Value

Hi,
Is it possible to add the Current Date (and Time) for the Default Value of a
Datetime-field in a table? I would like to do this without Stored
Procedures, so I guess this can be done by formatting the Default Value, but
I can't find out how :-/
Anybody knows if tihs is possible, and if so, how? :-)
Thanks a lot in advance!
PieterOk I jsut foudn out that I can use CURRENT_TIMESTAMP and GETDATE() for it
:-)
Thanks anyways! :-)
"DraguVaso" <pietercoucke@.hotmail.com> wrote in message
news:exLkPdeUEHA.544@.TK2MSFTNGP11.phx.gbl...
> Hi,
> Is it possible to add the Current Date (and Time) for the Default Value of
a
> Datetime-field in a table? I would like to do this without Stored
> Procedures, so I guess this can be done by formatting the Default Value,
but
> I can't find out how :-/
> Anybody knows if tihs is possible, and if so, how? :-)
> Thanks a lot in advance!
> Pieter
>|||Dragu
CREATE TABLE #Test
(
[Date] DATETIME DEFAULT GETDATE()
)
GO
INSERT INTO #Test DEFAULT VALUES
GO
SELECT * FROM #Test
"DraguVaso" <pietercoucke@.hotmail.com> wrote in message
news:exLkPdeUEHA.544@.TK2MSFTNGP11.phx.gbl...
> Hi,
> Is it possible to add the Current Date (and Time) for the Default Value of
a
> Datetime-field in a table? I would like to do this without Stored
> Procedures, so I guess this can be done by formatting the Default Value,
but
> I can't find out how :-/
> Anybody knows if tihs is possible, and if so, how? :-)
> Thanks a lot in advance!
> Pieter
>|||Pieter,
you might also want to investigate the CONVERT function in BOL - it has an
optional third argument specifically used with datetime values to format
them according to different locale types.
HTH,
Paul Ibison

No comments:

Post a Comment