0

Hi all, I have created a table in which i have a DateTime Column . i need that i dont want to insert values in that column from the front end. i have created a trigger for that purpose. whenever i insert a row in that table the dateTime column must be updated with current date and time.

To show the current date and time we have
Select Getdate()

But how to use function in a insert command
Any idea plz

4
Contributors
6
Replies
9
Views
8 Years
Discussion Span
Last Post by Timothy_3
1
Insert Into aTable (SomeString, SomeDateTime) Values ('abc', GetDate())
Update aTable
Set SomeDateTime = GetDate()
Votes + Comments
Your always quicker to the draw..
0

Just insert the getdate().

If you want specific date formats look up the CONVERT function.

Insert into Table (date)
Values(getdate())
0

CONVERT(CHAR(10),GETDATE(),110) Will give you the format 02-05-2003 CONVERT(CHAR(10),GETDATE(),10) Will give you 02-05-03

The MSDN library will give you all the conversions. You can also create your own format if you wish with DATEPART functions.

0

If this is for insert only, then you'd be better off with a default value in the date column as you may not know that triggers run at a statement level, no a row level.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.