Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Date Integer value different from other programs by 2 days

Posted on 2009-04-06
6
Medium Priority
?
350 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 1000 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 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