Oracle Linked server date format issue from sql server 2008

Posted on 2010-09-24
Last Modified: 2013-12-18
I am trying to get date from oracle using linked server but the date format it is getting is like this

0009-01-10   for 2009-01-10.  does any one seens this issue before,
Question by:hp746
  • 4
  • 4
LVL 34

Assisted Solution

johnsone earned 500 total points
ID: 33755959
The format of the string that Oracle returns for a date is controlled by settings which you can change.

To change at the session level, you can use:


or any other variant of a date format (this is just an example).

It can also be changed at the database level by changing the same parameter.

There is also a registry setting that you can set to change the default format.

All of these will set defaults.  They can always be overridden at the query level with a TO_CHAR(<date_field>, 'MM/DD/YYYY'), again, any valid format is usable here.

Author Comment

ID: 33756079
Hi John,

This data i am pulling from SQL server 2008 using oracle linked server . here is the query.

SELECT DISTINCT date_effective FROM test_link..test_schema.test_m_view

its returning dates as  0009-11-21 00:00:00.0000000.  what could be the issue here.

LVL 34

Expert Comment

ID: 33756300
There is no issue.  What format do you want the date in?
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.


Author Comment

ID: 33757352
For 2009  its showing 0009  and for 2010  its showing 0010.
LVL 34

Expert Comment

ID: 33757687
Then your data is incorrect.  0009 and 0010 are valid years in an Oracle database.  If you insert a 2 digit year into a date field with a 4 digit year as a date mask, you will get that.

If you connect directly to the Oracle database using SQL*Plus, what do you see as a year for those records?  My guess is you will see 0009 and 0010.

I believe that if you change the date format to use RRRR rather than YYYY it should correct that.

Author Comment

ID: 33758287

Date is oracle is of this format  30-SEP-09 checked thru SQL plus.

I tried to convert using RRRR  as well but it is still returning year as 0009  and 0010.

This issue i am getting in staging server but in dev its returning 2009 and 2010 for year for same table structure and using same query.

Not sure whats going wrong here.  any help will be appreaciated.
LVL 34

Accepted Solution

johnsone earned 500 total points
ID: 33765451
When you are checking the date in SQL*Plus, you are only looking at the 2 digit year.  You need to check the 4 digit year.  Use TO_CHAR(<date_field>, 'DD-MON-YYYY HH24:MI:SS').  That will show you the whole date.  This should confirm what the full 4 digit year is on the Oracle side.

RRRR was a long shot, I wasn't sure that would work.  I don't have an Oracle database that I can try this on right now, but this conversion may work.

TO_DATE(TO_CHAR(<date_field>, 'MM/DD/YY HH24:MI:SS'), 'MM/DD/RR HH24:MI:SS')

What this should do is convert it to a string as a 2 digit year an then convert it back to a date using the RR format.  That should fix the year for you.  If that does not work, you are going to have to go through string manipulations to fix the dates.

Author Closing Comment

ID: 33833176
we have inhouse solution

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

Suggested Solutions

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

816 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

13 Experts available now in Live!

Get 1:1 Help Now