Solved

SQL Date Integer value different from other programs by 2 days

Posted on 2009-04-06
6
301 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
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.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now