How to Store Current Data Time To Database automatically.
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 24, 2014, 3:08 AM EDT
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.
Posted Mar 24, 2014, 3:18 AM EDT
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
Joginder BangerRank #360 · 7K reputationPosted Mar 24, 2014, 4:37 AM EDT
create proc mytest
(
@date=getdate(),
another column is here mention
)
as
begin
insert into tableName values(@id,@date);
end
return