I am trying to convert an integer datatype into a date. Here is the coding that I have so far:
SELECT CONVERT(column_name, yyyymm) from table_name; What do I need to add?
63 Answers
Assuming your integer column (say, your_column) is representing year and month in yyyymm format, this should work.
First, convert your int column to a varchar and then add '01' to make it yyyymmdd (ISO Format), then convert to datetime/date.
SELECT CONVERT(date, CONVERT(varchar(6), your_column) + '01') myDate FROM TableName 5select DateAdd(second, someNbrCol, '1970-01-01') The last argument you would have to provide as the starting date.
try
SELECT CONVERT(date, convert(char(8),20180521)) or
select FORMAT(CONVERT (date,convert(char(8),20180521)),'dd-MMM-yyyy')