June 12, 2008 at 1:37 pm
I'm importing an Excel spreadsheet into a SQLServer table. One of the columns I use is a serial date in the Excel source file e.g. 39623 which, when I format it in Excel, returns a date of 6/24/2008. The destination table in SQLServer is formatted as an int. When I CAST this to a DATETIME I end up with a different date i.e. 6/26/2008. Somehow I gained 2 days in the translation. Anyone else experienced this? I can work around it of course, but seems kind of strange that different MS products would handle differently. :crazy:
June 12, 2008 at 2:29 pm
hehe - It looks to me that the programmer in charge of date handling for excel was asleep at the wheel. Two things are causing your issue:
1. 0 doesn't mean the same thing to both systems. In Excel - formatting a 0 to be a date results in an invalid date ("01/00/1900", or in their definition - the day before 1/1/1900. Fancy that - I thought that was 12/31/1899...)
2. Excel incorrectly treats 1900 as a leap year (rule is: a year is a leap year if its divisible by 4 UNLESS it's divisible by 100 and NOT divisible by 400). So - february 1900 gets an extra day it didn't have.....
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
June 12, 2008 at 3:09 pm
The sad truth is that the Excel bugs are intentional "features" that were put in to match the behavior of Lotus 123 where the bug originated.
June 12, 2008 at 3:43 pm
Michael Valentine Jones (6/12/2008)
The sad truth is that the Excel bugs are intentional "features" that were put in to match the behavior of Lotus 123 where the bug originated.
It's actually a better reason than just plain screwing up. Thanks for the link back.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
June 12, 2008 at 7:17 pm
I'd like to know why people use Date Serials in such a fashion to begin with.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 13, 2008 at 4:50 am
Date "Zero" for SQL Server is 1900-01-01
Date "Zero" for MS Access is 1899-12-30
That's why there is a two day difference.
N 56°04'39.16"
E 12°55'05.25"
June 13, 2008 at 8:24 am
I hear you. Hey, the use of Excel wasn't my choice, but unfortunately I had to deal with it
June 13, 2008 at 12:12 pm
So if you want to keep dateserials, just add 2 to excels dateserial value and you're set.
Or convert excel dateserial back to date, export and convert back to dateserial.
N 56°04'39.16"
E 12°55'05.25"
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy