Solved

SQL Date Integer value different from other programs by 2 days

Posted on 2009-04-06
6
342 Views
Last Modified: 2012-05-06
If I convert a date to an integer in excel or sharepoint I get the same value.  For example, 3/10/03 converts to 37960.  If I convert that same date to an integer in SQL 2005 I get 37958.  What is causing the difference?
0
Comment
Question by:rkanter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 25

Expert Comment

by:reb73
ID: 24082711
The base date in SQL Server is 01-Jan-1900 while in VBA the base date is 30-Dec-1899 for some reason and this two days is the difference.. You can verify this using

select cast(0 as datetime)   -- TSQL will yield 01-Jan-1900

?CDate(0)                            -- VBA/VBScript will yield 30-Dec-1899

You can either use 2 as an offset or just deal with literal dates/native datetime datatype variables in each case..
0
 
LVL 28

Accepted Solution

by:
TextReport earned 250 total points
ID: 24082740
Each application has it's own start date for day 1, in MS Access it is 31/12/1899, Excel is 01/01/1900 (unless you have 1904 dates set then 1 becomes 2nd Jan 1904)
You do not rely on the INTEGER value from each application as to the date value, each has it's own rules. They should honour the dates being passed to them though.
Cheers, Andrew
0
 

Author Comment

by:rkanter
ID: 24083065
reb73 - thanks for the information.  When I googled 'date integer values' they alll seem to indicate that SQL uses the same start date.
Textreport- the problem is I am comparting a value in sharepoint to a value in SQL.  If I just do a date comparison it fails.  If I pad it with a couple of days it works.
0
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 
LVL 28

Expert Comment

by:TextReport
ID: 24084439
When you are comparing the value in SharePoint and SQL Server what method are you using to retrieve the data from both Sharepoint and SQL Server, there should be a way to retrieve the values as native dates rather than integers.

Finally please note the difference in EXCEL with the value in the spreadsheet vs the value in a cell and that the 1904 date option only affects the spreadsheet and not VBA.

Cheers, Andrew
0
 

Author Comment

by:rkanter
ID: 24088870
Orginally I was just comparing the valies, select .... where sharepointdate = sqldate....  When it failed I decided to just query the values.  Sharepoint gave me the integer value and sql gave me a date.  I tried to convert the integer value of sharepoing to a date, but it is off by two days from how it appears on sharepoint.  If I just subtract 2 that everything works, which it sounds like is the easiet solution.  I would just hate for this to fail again after MS decided to change the start date in some service pack
0
 
LVL 28

Expert Comment

by:TextReport
ID: 24088896
Sorry but I don't know enough about sharepoint to comment on that side, working between Access or Excel and SQL then the way you query the data takes starting date into account.
Cheers, Andrew
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question