MSExcel和SQL Server中日期时间转换之间的差异 [英] Difference between datetime converts in MSExcel and SQL Server

查看:212
本文介绍了MSExcel和SQL Server中日期时间转换之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我在进行工作时发现在Excel中将日期时间转换为文本,并在SQL Server中使用其生成的数字将日期时间转换为日期时间,确实发现了一些奇怪的东西。

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.

我在Excel中假定今天为(2014/05/20 dd / MM / yyyy)文本中得到41779。

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

我得到了文本值,我使用SQL转换为 datetime 来检索该值作为日期,但没有得到我想要的结果。

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.

我什至用 datetime2 进行了测试,但我知道我无法转换 int datetime2

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

我既不是MS Excel专家,也不是SQL Server专家,但是怎么回事?我可以通过执行MS Excel生成的数字并删除2使其工作,但对我而言仍然没有意义。

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.

推荐答案

hehe;)一天以前,我想知道同样的事情...做一个简单的练习:

hehe ;) one day ages ago I wondered the same thing... do a simple exercise:

比较选择Cast(0作为DateTime ) = DATEVALUE( 1900-01-01) 可以解释1天的差异

,并通过阅读 VBA之父Joel Spolsky,解释

tl; dr

差异-第二天结束

= DateValue( 1900-02-28) = DateValue( 1900-03-01)

这篇关于MSExcel和SQL Server中日期时间转换之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆