question

VAIBHAV avatar image
VAIBHAV asked

sql server 2008

how to get current date in database column, while entering each entry in other columns..? i don't want to add date in date column manually??
sql-server-2008
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
aRookieBIdev avatar image
aRookieBIdev answered
Use GETDATE() function to get the current date. To get in a particular format you just have to convert them accordingly. example select GETDATE() select convert(varchar,getdate(),102) select convert(varchar,datepart(yy,getdate())) + '-' + convert(varchar,datepart(mm,getdate())) + '-' + convert(varchar,datepart(dd,getdate()))
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Dave_Green avatar image Dave_Green ♦ commented ·
You could also consider adding the GETDATE() function as the default for the column in the table if the data item is always going to be the current date (e.g. a 'last updated' column). Then simply omit the column from your update statement and SQL Server will automatically insert the date to the column.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.