Custom DateTime format for Oracle Database

I'm currently reading DateTime items from an Oracle database, which are in the format dd/mm/yyyy hh:mm:ss, but I need them to be stored as follows: yyyy-mm-dd hh:mm:ss.

I've tried two approaches. The first I've tried splits a string version of the date into parts and reassembles it to give me the output I desire. However, converting this to a DateTime object reverts it to the original format. Here's the code:

public static DateTime FormatDateTimeForPDB(string dateTimeString)
    DateTime formattedDateTime;
    char[] illegals = { '/', ' ', ':' };

    string[] array = dateTimeString.Split(illegals);
    string date = array[2] + "-" + array[1] + "-" + array[0] + " " + array[3] + ":" + array[4] + ":" + array[5];

    formattedDateTime = Convert.ToDateTime(date);      
    return formattedDateTime;

A breakpoint at Convert.ToDateTime(date) shows date as 2012-09-07 15:01:03 which is the format I want, but as a string, not a DateTime.

I've also tried using the DateTimeFormatInfo attribute as discussed by the user tatis over here, but all that managed to do was swap the month and day fields (giving me mm/dd/yyyy hh:mm:ss). Any help would be greatly appreciated.


If you are worried about parsing the date string into a DateTime in C# take a look at DateTime's ParseExact method. Documentation here.

Something like this:

CultureInfo provider = CultureInfo.InvariantCulture;
String format = "dd/MM/yyyy hh:mm:ss";
return DateTime.ParseExact(dateString, format, provider);

Need Your Help

How to get the length of http response python scapy

python http tcp scapy

So I am writing a python scapy script that will first just complete a 3 way handshake, send an http get, and then close the connection.

How do I automatically update cells to match values from another sheet when one cell is changed using data validation?


I have a list of items on Sheet 1 with the names of each item in column A and then further information in the subsequent 5 columns.