-1

Want to update from data type of Date which is now 1980-12-17 00:00:00.000 to 17-Dec-80 in Microsoft SQL Server management studio

and I m trying to do update command

UPDATE emp SET HIREDATE = 17-Dec-80 WHERE EMPNO= 7369;

But I'm getting error.

Msg 207, Level 16, State 1, Line 1 Invalid column name 'Dec'

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843

3 Answers3

0

You can try something like this:

UPDATE emp
SET HIREDATE = '17-Dec-80'
WHERE EMPNO= 7369;

For more info visit this LINK

Buchiman
  • 310
  • 5
  • 18
0

As a_horse_with_no_name says in the comments, a DATE column doesn't have a format, what you're seeing when you SELECT it is a default human readable format of the date. If you want to see something different you specify your required format.

SELECT FORMAT(HIREDATE, 'dd-MMM-yy')
  FROM emp

Should do the trick.

OTTA
  • 1,041
  • 7
  • 8
0

To set the date use:

UPDATE emp SET HIREDATE = '17-Dec-80' WHERE EMPNO= 7369;

To retrieve it in the "dd-MMM-yy" format:

select 
   format(HIREDATE, 'dd-MMM-yy') as HIREDATE  
from emp 
WHERE 
   EMPNO= 7369
wnutt
  • 409
  • 3
  • 4