Friday, March 28, 2014

NET : Formatting A Date For Oracle

Currently, developers must provide date format whenever inserting date records into oracle.  Here is one approach:


public static DateTime FormatDateForOracle(string inDate)
  {
  //try to parse date into the acceptable Oracle format
  DateTime parsedDate;

  if (DateTime.TryParse(inDate, out parsedDate))
  {
    try
        {
          return parsedDate =       DateTime.ParseExact(Convert.ToDateTime(inDate).ToString("MM/dd/yyyy"), "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
        }
    catch (Exception e)
        {
          //Handle as you see fit
        }
  }
  else
    {
       //Handle as you see fit
    }
    return parsedDate;
}

No comments:

Post a Comment