Reputation: 55
I am trying to insert date into a table but the date and format of inserted date is messed up. The datatype in the table is Date
. My insert script is as below.
insert into Trans(ID, TDate, Description)
values(1, CONVERT(datetime, 25-02-2012, 101), 'Opening')
I am trying to insert in dd/MM/yyyy
format and I want it in the same format in my table. But in my table the date is 1894-07-22
!!
I want the date to be inserted exactly as the format I wish and I want to see the inserted date as 25-02-2012
in the table.
What is wrong here ? Can somebody help ?
Upvotes: 5
Views: 26977
Reputation: 1
insert into emp
(EMPNO,ENAME,DEPTNO,JOB,SAL,COMM,MGR,HIREDATE)values
(7839,'KING',10,'PRESIDENT',5000,NULL,NULL,'17-11-81')
Upvotes: -1
Reputation: 247690
you should use single quotes around your date. If you want date format of dd/mm/yyyy
format then you will want to use the convert(datetime, '25-02-2012', 103)
insert into Trans(ID,TDate,Description)
values(1,CONVERT(datetime,'25-02-2012',103),'Opening')
if you use convert(varchar, getdate(), 101)
the format of the date will be mm/dd/yyyy
.
There are several helpful links to use as a reference for datetime conversions:
Upvotes: 0
Reputation: 8959
Try CONVERT(datetime ,'25-02-2012', 103)
Upvotes: 3