I used DamithSL's solution, with a tweak, (I keep small console applications laying around for reference), and added a way to return the value to a string.
Hope this can be useful to someone else :-D
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ParseDateTimeYYYYMMDDconsole
{
class Program
{
static void Main(string[] args)
{
string str = "20140429";
string[] format = { "yyyyMMdd" };
DateTime date;
string ReStringed;
if (DateTime.TryParseExact(str,
format,
System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.DateTimeStyles.None,
out date))
{
Console.WriteLine("The raw string of YYYYMMDD date:");
Console.WriteLine(str);
Console.WriteLine("Date given after conversion to DateTime:");
Console.WriteLine(date);
ReStringed = date.ToString("yyyyMMdd");
Console.WriteLine("The date re-converted
back to a string, formatted yyyyMMdd:");
Console.WriteLine(ReStringed);
Console.ReadLine();
}
}
}
}