Convert string to DateTime object

Two C# functions that may be useful in accepting date/time strings of various formats:

        /// <summary>
/// Converts date string value, of various formats into DateTime object.
/// Example formats are DDMMYYYY,DD/MM/YYYY,MM/dd/YYYY,MMDDYYYY,...
/// </summary>
/// <param name="dateValue">date string</param>
/// <returns>resulting DateTime object</returns>
public DateTime ConvertDateStringToDateTime(string dateValue) {
string[] dateFormats = { "MM/yyyy",
"M/d/yyyy", "M/dd/yyyy", "MM/dd/yyyy",
"dd/MM/yyyy", "ddMMyyyy","dd/MM/yyyy","MMddyyyy",
"MM-dd-yyyy" };
try {
return DateTime.ParseExact(dateValue, dateFormats, CultureInfo.CurrentCulture, DateTimeStyles.None);
} catch (FormatException fe) {
throw new DataException(dateValue + ": " + fe.Message);
}
}

/// <summary>
/// Converts a time string of various formats into a DateTime object.
/// Example formats are: 7:00,700AM, 7:00AM, 7:00A, 0700AM, 07:00 AM, ...
/// </summary>
/// <param name="timeValue">time string</param>
/// <returns>resulting DateTime object</returns>
public DateTime ConvertTimeStringToDateTime(string timeValue) {
string[] timeFormats = {"HHmm","Hmmtt",
"H:mm", "H:mmtt", "H:mmt", "HHmmtt", "HH:mm tt", "HH:mmtt","HH:mmt", "HHmmtt", "HHMMt"};
// DateTime string cannot be blank, so if it is, assume "00:00"
if (string.IsNullOrEmpty(timeValue)) timeValue = "00:00";
try {
return DateTime.ParseExact(timeValue.ToUpper(), timeFormats, CultureInfo.CurrentCulture, DateTimeStyles.None);
} catch (FormatException fe) {
throw new DataException(timeValue + ": " + fe.Message);
}
}

Blog v3.0

This old techie blog of mine seemed to be dead silent lately that I feel compelled to resurrect it.

Let’s review a bit of history: In my mind, version 1.0 of my blog was on Bloglines (circa 2004). Version 2.0 was when I switch to blogspot and using the Kubrick theme.  It’s now time once again to resharpen the toolkit, beginning with a fresh new look, hat tip to the fine folks at Deluxe Templates for the iNove theme

TODO: I like this theme, but one thing I might change is to make a little more room for the content pane.

Also trying to install Alex Gorbatchev’s SyntaxHighligher scripts. Let’s see if this works:

    /**
* Sample code in C# to test SyntaxHighlighter.
*/
public Argument ArgueWith(Person person) {
if (person == null) {
throw new ArgumentException("no object to argue with");
}
// prepare argument
Argument arg = new Argument(person);
return arg;
}


Update 01/30/2011 11:44pm EST: SyntaxHighlighter worked great. I had to use dropbox.com to host the scripts. I think I spotted a bug, though, on Safari for iOS 4.1: line number is a bit out of whack.  Let’s have a closer look at PasteBin, as Gavin suggested: