Friday, October 12, 2007

Oracle SQL and C# Dates

If you are working with Oracle and C#, you may need to insert a Date into the database. The way this is done, is to specifiy a date format and then let Oracle know what the format is by using the "to_date" function. One of the problems is that C# and Oracle specifiy date formats differently.

Here is one example:
strFromDate = myFromDate.ToString("MM/dd/yyyy hh:mm:ss tt");
strToDate = myToDate.ToString("MM/dd/yyyy hh:mm:ss tt");

_sqlQuery += "AND DATE_COMPLETED >= to_date('" + strFromDate + "', 'MM/DD/YYYY HH:MI:SS PM') ";
_sqlQuery += "AND DATE_COMPLETED <= to_date('" + strToDate + "', 'MM/DD/YYYY HH:MI:SS PM') ";

No comments:

Check This Out!

More Links to Good Information