Total PageViews

Wednesday, March 30, 2022

How to convert excel imported decimal date value to real date in SQL Server

Suppose we have one excel sheet that we have imported into a table i.e. “Emp” after records are imported from excel to the table through import wizard date changes to some decimal value now condition is to convert that decimal value to the real date.

Query: select Id, CreatedDate from Emp

O/P:


Id

CreatedDate

101

42741.630556



Here we can see my CreatedDate column changed to some decimal value now we need to convert it into a real date i.e provided in an excel file.

Query: select Id, CreatedDate,

              CAST(CAST(CreatedDate AS FLOAT) -2 AS datetime) as RealDate

      from Emp

O/P: 

Id

CreatedDate

RealDate

101

42741.630556

2017-01-06 15:08:00.040





What other ideas can you add to this post that I may have not mentioned?

No comments:

Post a Comment