Reputation: 73
I'm trying to insert a timestamp within a data entry and I'm unsure what I'm doing wrong.
INSERT INTO dbo.SALES (
Sales_No
,Customer_ID
,Shop_No
,Staff_No
,DATE
,Sum_total
)
VALUES (
9876
,11223344556
,1000
,9000
,CURRENT_TIMESTAMP
,50900
);
I'm still learning how to do this so any help would be helpful.
Upvotes: 0
Views: 14902
Reputation: 31993
i just create one field and insert current timestamp
create table t(date smalldatetime);
insert into t values(CURRENT_TIMESTAMP);
select * from t
http://sqlfiddle.com/#!18/bf41ce/2
date
2018-08-31T06:22:00Z
So i think you need to change your datatype of your table column
Another way if you design your table in default clause no need insertion explicitly
CREATE TABLE test ( aa int,
dd DATETIME DEFAULT GETDATE()
);
insert into test (aa) values(1)
insert into test (aa) values(2)
insert into test (aa) values(3)
aa dd
1 2018-08-31T08:08:14.49Z
2 2018-08-31T08:08:14.49Z
3 2018-08-31T08:08:14.493Z
sqlfiddle.com/#!18/b5fdd/1
Upvotes: 1
Reputation: 464
You can also use getutcdate() to get the current timestamp if your datatype is datetime
Upvotes: 0