Solved

SQL Date Integer value different from other programs by 2 days

Posted on 2009-04-06
6
323 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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