Click here to Skip to main content
15,906,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
String was not recognized as a valid DateTime.



ExpiryDate = DateTime.ParseExact(model.ExpiryDate.Replace("-", "/"),MM/dd/yyyy, null),


model.ExpiryDate is my model field that is a string value,

im my DB ExpiryDate is Date Time


I Cant Convert string to Date Time With Correct Format


Plz Help...
Posted
Comments
ZurdoDev 17-Dec-15 8:22am    
You don't have a valid datetime value. Put a breakpoint there and see what the data is and you should have this fixed quickly.


  1. I assume you just forgot the quotation marks around MM/dd/yyyy here.
  2. Your input date string does not match the formats "MM/dd/yyy" or "MM-dd-yyyy".
  3. The format "MM-dd-yyyy" is uncommon (English date format with '-' separator).

To find out what applies, you should print out model.ExpiryDate to see which format is used.
 
Share this answer
 
C#
<globalization enableclientbasedculture="true" culture="auto:en-GB" uiculture="auto:en" />


add this one to Web.config
 
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