Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8450715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:02:51+00:00 2026-06-10T11:02:51+00:00

Okay, I’m trying to get the String value of a DATE column in Oracle

  • 0

Okay, I’m trying to get the String value of a DATE column in Oracle 11g to pass along to the UI in a C# app (via WCF). I want to display exactly what I’m pulling back in SQL Developer to a string variable in C#. Instead, when I’ve got a Date column, I’m getting some really wacky parsed DateTime values instead.

Examples:

Value in SQL Developer: 26-AUG-75
Value from myDataRow[0].ToString() in VS: 8/26/0975 12:00:00 AM

Value in SQL Developer: 01-JUL-76
Value from myDataRow[0].ToString() in VS: 7/1/1776 12:00:00 AM

The Oracle dates look right. VS’s don’t. Thanks, Ben Franklin and Edward the Martyr. What the heck?

The SQL’s pretty plain. I’m obviously changing field names, but this is it:

SELECT DISTINCT(MyDate) FROM
User1.TableOfDates@DateTableLink 
WHERE MyDate IS NOT NULL ORDER BY
MyDate

The shared code to throw SQL against the db is pretty plain as well. I’m going to censor it a good deal here, but it works well everywhere else so far, and I think I’ve got the important stuff here:

internal Oracle.DataAccess.Client.OracleConnection oracleConn;
...
DataTable dtReturn = new DataTable();
Oracle.DataAccess.Client.OracleCommand cmdTemp = null;
string strScrub = "";

// strScrub is magically loaded with SQL, which is, 
// if you grab it with a breakpoint here, after it's 
// scrubbed, equal to what I've written, above

cmdTemp = new Oracle.DataAccess.Client.OracleCommand(strScrub, this.oracleConn);
Oracle.DataAccess.Client.OracleDataReader dr = cmdTemp.ExecuteReader();
dtReturn.Load(dr);
dr.Dispose();
...
return dtReturn;

That part works. I only include it here in case there’s something from using Oracle.DataAccess that I should be aware of. Everything’s opened and closed and collected just fine. We’re throwing hundreds of commands through it each day in dev, and at least thousands on deploy.

Here’s some info from the immediate window for the first value (26-AUG-75), with dr now representing a single DataRow from the DataTable pulled from the code, above:

? DateTime.Parse(dr[0].ToString())
{8/26/0975 12:00:00 AM}
    Date: {8/26/0975 12:00:00 AM}
    Day: 26
    DayOfWeek: Saturday
    DayOfYear: 238
    Hour: 0
    Kind: Unspecified
    Millisecond: 0
    Minute: 0
    Month: 8
    Second: 0
    Ticks: 307569312000000000
    TimeOfDay: {00:00:00}
    Year: 975

And with just ? dr[0] — which gives the same thing:

?dr[0]
{8/26/0975 12:00:00 AM}
    Date: {8/26/0975 12:00:00 AM}
    Day: 26
    DayOfWeek: Saturday
    DayOfYear: 238
    Hour: 0
    Kind: Unspecified
    Millisecond: 0
    Minute: 0
    Month: 8
    Second: 0
    Ticks: 307569312000000000
    TimeOfDay: {00:00:00}
    Year: 975

Now interestingly that says it’s a DateTime when it’s just a Date in Oracle. Maybe I’m missing something about Oracle Dates…

? dr[0].GetType()
{Name = "DateTime" FullName = "System.DateTime"}

Anyhow, if I could get to the same value I see in SQL Developer (eg, 26-AUG-75), I’m fine. I can take that and do whatever I want.

Where is the implicit conversion going on, and how can I get in there a little earlier?

I should add that I can’t get creative with the SELECT statement & TO_CHAR. This is all a fairly complex automated process that builds queries based on user criteria. So changing this SELECT would be a “give a machine a fish” not “teach the machine to fish” answer. Any field could be a date in this format, so switching on GetType values and parsing some creative way in C# is fine, but changing the SQL isn’t.

EDIT Using a suggestion from here:

select dump(sysdate)today from dual; 

Using dump in the above SQL, run from SQL Developer, I get:
Typ=12 Len=7: 119,175,8,26,1,1,1 for 26-AUG-75’s row. So Oracle’s got the right date.

Following the conversion instructions found here…

119 - 100 "excess" = 19 centuries == 1900
175 - 100 "excess" = 75     years ==   75

That’s 1975.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:02:53+00:00Added an answer on June 10, 2026 at 11:02 am

    It’s not clear from your question, but I assume you actually wanted 1975 and 1976?

    I strongly suspect that the values 0975 and 1776 are actually what are in the database. Your values in SQL Developer are just a 2-digit-year representation of that. I suspect that if you perform a different kind of string conversion which uses a 4-digit-year representation, you’ll see the same values.

    So, options after validating that the above is correct:

    • Work out how the bad data got in the system, fix that (so you don’t get any more bad data) and then fix the existing data.
    • Work around the issue by ignoring all but the last two digits of the year, and forcing them to an appropriate century. Note that there could be some “interesting” data around in terms of Feb 29th being valid in some years but not others…

    I’d strongly suggest casting to DateTime rather than converting to a string and then parsing it, by the way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so the title may be a bit misleading. What I am trying to
Okay, so I'm trying to make a game that uses this algorithm: http://www.codeproject.com/Articles/15573/2D-Polygon-Collision-Detection But
Okay, I'm trying to reverse engineer a feature on a website I found -
Okay, here is one weird bug... In my app, I load multiple xml files.
Okay so here is what I'm trying to accomplish. First of all below table
Okay say your using a app, and you opened a new activity and then
Okay, I am using a custom tab bar (not a tab based app) but
Okay this might be confusing. I'm trying to make a config class for myself
Okay, I've looked all over the internet for a good solution to get PHP
Okay, my code is currently: public MySqlDataReader CreateQuery(string queryString, string connectionString ) { using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.