Click here to Skip to main content
15,944,837 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code block as below:

DateTime fromdate = null;
String dateTime = "09-07-2010 00:00:00"
fromdate = DateTime.ParseExact(dateTime, "dd-MMM-yyyy HH:mm:ss", null);

It is giving error while Parsing. Can anyone tell me why it is giving error?

Thanks in advance.
Posted

Did you pasted exact code fragment? Why there is "dd-MMM-yyyy ...". I don't think tripple M is correct month format.
 
Share this answer
 
Comments
bedathur_ganesh 9-Jul-10 6:13am    
yes.. I did mistake. I was using dd-MMM-yyyy. But, it should be dd-MM-yyyy. Now its working. Sorry.. Thanks..
Hi bedathur_ganesh,

Have you tried using .Parse instead of .ParseExact? If your date is in the format like the value of string dateTime, then using ParseExact will fail since the format of the dateTime's value is dd-MM-yyyy hh:mm:ss and you want to parse it exactly in dd-MMM-yyyy HH:mm:ss.

You can read more from this link.[^]

@helianthus87 - MMM is allowed format for month. This is the 3-letter representation of month (e.g. Jan, Feb, Mar, etc.).

Hope this helps.
 
Share this answer
 
Comments
sidbaruah 9-Jul-10 6:49am    
Reason for my vote of 5
changing MMM to MM in the code would do the trick! :)
/randz 9-Jul-10 6:56am    
:-) i actually was not paying attention much. i did not noticed that removing the M on his ParseExact would actually be equivalent to the format of his string dateTime. silly me :-). thanks for noticing.

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