How to Store Current Data Time To Database automatically.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Joginder BangerPosted Mar 24, 2014, 8:37 AM
create proc mytest
(
@date=getdate(),
another column is here mention
)
as
begin
insert into tableName values(@id,@date);
end
return
Posted Mar 24, 2014, 7:18 AM
To store current date time in sql database table you need a column having datetime data type and while inserting use getdate function in your sql statement
for example
suppose your Table Name is abc and date filed column is cdate
create table abc
(
id int,
cdate datetime
)
sql statement
insert into abc (id,cdate) values (1, getdate());
or
in ado.net
write Sqlcommand.Text="insert into abc (id,cdate) values (1," +System.DateTime.Now.Date+")";
kindly accept as answer, if it helps you
Jignesh TrivediPosted Mar 24, 2014, 7:08 AM
hi,
are you want to store current date time to any particular column of SQL table?
If yes than you can set default value for the column.
like
CREATE TABLE table1
(
Id int NOT NULL PRIMARY KEY,
Name varchar(50) NOT NULL,
OrderDate datetime NOT NULL DEFAULT GETDATE()
)
or
ALTER TABLE Table1 ADD CONSTRAINT DF_Constrain_Name DEFAULT GETDATE() FOR columnName
hope this will help you.