Click here to Skip to main content
16,009,728 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Can any one help me for how to convert string date value .
My Code is

string value="10 112009";
It is in ddMMYYYY fromat.
How can i convert this in YYYYMMDD format and add this value to list<string>.

please help me.
Posted
Updated 3-Apr-13 20:41pm
v2

Hi
C#
string dateString = "10112009"; 
    string format = "ddMMyyyy";
    DateTime dateTime;
    if (DateTime.TryParseExact(dateString, format, CultureInfo.InvariantCulture,
        DateTimeStyles.None, out dateTime))
    {
        Console.WriteLine(dateTime.ToString("YYYYMMDD"));
    }


You will get date value in dateTime object then you can perform
dateTime.ToString("YYYYMMDD") and get desired value.
 
Share this answer
 
Comments
Anurag Sinha V 4-Apr-13 2:45am    
elegant solution buddy..+5 from me..
have used TryParseExact numerous times..

-Anurag
Maciej Los 4-Apr-13 3:09am    
+5
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900