473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Why does SQL calc float dates different than Excel

If I enter the value 39301.5 into a cell and format it as date, I get the following result:
08/07/2007 12:00 PM

However, if I put 39301.5 into this statement in SQL:
Expand|Select|Wrap|Line Numbers
  1. Select cast(39301.5 as datetime)
I get the following result:
2007-08-09 12:00:00.000

Its off by 2 days... Whats up with that?

I only ask because I have another app (not excel) that is working like excel and I need it to work like SQL. I know I could simply use DATEADD to adjust the output by 2 days... but I really wonder whats going on.
Aug 10 '07 #1
2 3554
Ok, so I figured out why excel reads 2 days off of MS SQL.

The first day is lost because Excel starts counting from 1, rather than 0. Enter a 0 into excel and have it convert it to a date and you get 1/0/1900. This isn't a real day, so it is assumed that Excel really starts its counting on 12/31/1899.

The second day is lost because of a bug between Microsoft and Pope Gregory the 8th. In 1582 the Roman Calendar was revised (and subsequently named the Gregorian calendar). One of the new revisions was that every 100 years there would not be a leap day. Enter 60 into excel and you'll get 2/29/1900. This day doesn't exist in the gregorian calendar.

So, since SQL starts with day 0 equaling 1/1/1900 and doesn't contain the extra fictitious day they are off by 2 days from each other.
Aug 10 '07 #2
teddarr
143 100+
Hmm. I knew about the 1st error, wasn't aware of the second. Thanks for posting your discovery. Please continue to do so.
Aug 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Riley | last post by:
The date fields being saved by a VB program were being saved as #2003-11-22#. For reasons unknown to me these dates began to be saved as "11/22/2003" All of these dates were made dates with the...
3
by: Astra | last post by:
Hi All Wonder if you can help me with the following calc, which I want to create to check whether or not a user has entered a valid credit card expiry date: 1) I have retrieve a value from 2 x...
12
by: Susan Cranford | last post by:
Please forgive, I have looked at so much info I can't figure out how to put it together even though I know it must be fairly simple. I have an array of input text boxes (txtDOBn) where n is...
24
by: PromisedOyster | last post by:
Is there a way that I can get a resultset that contains unique dates in a given date range without the need to have a temporary table and a cursor? perhaps something like: declare @start_date...
2
by: BlackFireNova | last post by:
I have an Access 2003 mdb which contains software records. I need to sort on a particular type of software, and then identify and count how many copies there are per each group of that type...
6
by: vj | last post by:
I have a program which generates xml files for excel but these files are not recognized by open office calc. I looked at the OO uno library, but it seems like an over kill. In my experience, for...
130
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places...
2
by: tasmontique | last post by:
I am working on an access 2002 flight schedule database. I am new to access but have some basic understanding of sql and vb6 code. I have learned a lot from this website. Thanks much Hopefully...
0
by: amit dutta | last post by:
while executing the following code i am getting error message as "methods and variable not defined and also " com.sun.star.uno.runtime exception" Change the code for me as per request....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.