I have a String stored in this format "10/10/2009 12:00:00".
I would like to convert this into a DateTime object so I can add it into the Outlook calender.
I have tried using the following code but it doesnt seem to work.
DateTime startDate = DateTime.Parse(appointments);
(where appointments is a string in a point in an array)

I have also tried using the following code to parse butit hasnt lead to anything for me:
System.Globalization.DateTimeFormatInfo info = new System.Globalization.DateTimeFormatInfo();

Can somebody show me how to parse the above format or by another method i cant seem to get to work either way. Many thanks

Recommended Answers

All 9 Replies

Thanks very much for the information:)

I have tried this but it still doesnt seem to work correctly. In the database, i have s string stored as "10/11/2009 13:00:00" which is the date.

The code below is what i use to read from the database butonly the first line works...

string temps = reader.GetString(4); 
DateTime datetimeStart = DateTime.ParseExact (temps, "MM/dd/yyyy hh:mm:ss", System.Globalization.CultureInfo.CurrentCulture);

Could you point me as to where im going wrong or a better way to achieve what im trying to do?

What error do you get? The code looks right so it should convert the string.

Hi,

Could you also give a try like this way;

string temps = "10/11/2009 13:00:00";
DateTime datetimeStart = Convert.ToDateTime(temps, System.Globalization.CultureInfo.CurrentCulture);

Good luck.

Are you shure that appointments is the correct string. I tried DateTime.Parse("10/10/2009 12:00:00") and it works fine.

DateTime datetime = DateTime.ParseExact("10/10/2009 12:00:00", "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

Assuming the 10/10/2009 is day/month/year and really, the above solutions should work just fine.

DateTime datetime = DateTime.ParseExact("10/10/2009 12:00:00", "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

Assuming the 10/10/2009 is day/month/year and really, the above solutions should work just fine.

You mean month/day/year, surely? :)

Err yes sorry :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.