views:

505

answers:

3

Hello,

I have a .Net webapp that is connecting to an Oracle backend. I have a base page which every page uses where I set my

    protected override void OnPreInit(EventArgs e)
{
    System.Globalization.CultureInfo cultureInfo =
        new System.Globalization.CultureInfo("en-CA");

    // Creating the DateTime Information specific to our application.
    System.Globalization.DateTimeFormatInfo dateTimeInfo =
        new System.Globalization.DateTimeFormatInfo();

    // Defining various date and time formats.
    dateTimeInfo.DateSeparator = "/";
    dateTimeInfo.LongDatePattern = "dd-MMM-yyyy";
    dateTimeInfo.ShortDatePattern = "dd-MMM-yyyy";
    dateTimeInfo.MonthDayPattern = "dd/MM";
    dateTimeInfo.LongTimePattern = "HH:mm";
    dateTimeInfo.ShortTimePattern = "HH:mm";
    dateTimeInfo.FullDateTimePattern = "dd-MMM-yyyy";

    // Setting application wide date time format.
    cultureInfo.DateTimeFormat = dateTimeInfo;

    // Assigning our custom Culture to the application.
    //Application.CurrentCulture = cultureInfo;
    Thread.CurrentThread.CurrentCulture = cultureInfo;
    Thread.CurrentThread.CurrentUICulture = cultureInfo;
    base.OnPreInit(e);
}

In my application I use an OracleDataAdapter to execute plain text queries on the database. I am filtering dates like so

"MyDateColumn" = '01-Jan-2000'

This works fine on my local. However when I get to the server the only dates that work in my filter are in the format

"MyDateColumn" = '2000 Jan 01'

What am I missing?

+2  A: 

Hi Biff,

you should always explicitely compare DATE columns to DATE values, i-e:

"MyDateColumn" = to_date('01-Jan-2000', 'dd-Mon-yyyy')

Never rely on implicit date conversion.

Vincent Malgrat
+1  A: 

Try:

"MyDateColumn" = to_date('01-Jan-2000','DD-MON-YYYY')

instead of relying on implicit conversions from string to date.

Rob
A: 

Where dt is a variable of type DateTime, try the following

to_date('" + dt.ToString("MM/dd/yyyy HH:mm:ss") + "', 'MM/dd/yyyy HH:mi:ss')

Eric Khosa