Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between datetime converts in MSExcel and SQL Server

Tags:

People also ask

What is the format of DateTime in SQL Server?

SQL Server comes with the following data types for storing a date or a date/time value in the database: DATE - format YYYY-MM-DD. DATETIME - format: YYYY-MM-DD HH:MI:SS.

How can convert date and time in SQL Server?

We can convert the Date into Datetime in two ways. Using CONVERT() function: Convert means to change the form or value of something. The CONVERT() function in the SQL server is used to convert a value of one type to another type. Convert() function is used to convert a value of any type to another datatype.

How do I convert DateTime in Excel?

The DATEVALUE function in Excel converts a date in the text format to a serial number that Excel recognizes as a date. So, the formula to convert a text value to date is as simple as =DATEVALUE(A1) , where A1 is a cell with a date stored as a text string.


I have found something really weird today while doing a work converting a datetime to text in excel and using the number generated by it to convert to datetime in SQL Server.

What is weird about it? Different results. Two days difference to be precise.

I assumed the date of today (20/05/2014 dd/MM/yyyy ) in Excel and got 41779 as result in text.

Datetime input

Convert to text

I got the text value and I use SQL convert to datetime to retrieve the value as date and I did not get the result I wanted.

SQL Convert to datetime

I even tested with datetime2 but I learned that I can't convert int to datetime2

enter image description here

I'm not a MS Excel expert nor a SQL Server expert, but what is going on? I can make it work by doing the number generated by MS Excel and removing 2, but still doesn't make sense to me.