Click here to Skip to main content
16,000,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i would like to convert the string "27/06/2012" to datetime .
Can any body please help.?
I Tried using Datetime.parseexact Method , but it is giving wrong date.
Posted

Try this:
C#
DateTime myDate = DateTime.ParseExact("27/06/2012", "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture)

Or
C#
DateTime oDate = DateTime.Parse(string s);


Refer:
Convert.ToDateTime Method (String)[^]

I Tried using Datetime.parseexact Method , but it is giving wrong date.
What exactly it's giving, can you post that wrong date.
 
Share this answer
 
Comments
raki1111 27-Jun-12 3:24am    
the date which i getting is #1/27/2012 12:06:00 AM#
Prasad_Kulkarni 27-Jun-12 3:26am    
In which format you want it then??
raki1111 27-Jun-12 3:30am    
Please see the date which i mentioned above , it is giving me the wrong month
raki1111 27-Jun-12 3:27am    
Please see the date which i mentioned above , it is giving wrong month
Prasad_Kulkarni 27-Jun-12 3:30am    
Try my second answer: DateTime oDate = DateTime.Parse(string s);
C#
Convert.ToDateTime("27/06/2012");


I hope it will work.....
 
Share this answer
 
v2
Comments
raki1111 27-Jun-12 3:17am    
Error Raised is "String was not recognized as a valid DateTime."
Upniwesh 27-Jun-12 3:27am    
Convert.ToDateTime("27/06/2012","DD/MM/YYYY")
try this........
raki1111 27-Jun-12 3:34am    
vb.net doesnt support above signature.

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