Solved

SQL Date Integer value different from other programs by 2 days

Posted on 2009-04-06
6
335 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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why do I get extra rows when I do inner join? 12 43
Need help with a query 6 81
How can I get this column in my query? 2 57
CREATE DATABASE ENCRYPTION KEY 1 80
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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