SHARE
TWEET

Giving System.FormatException: String was not recognized as a valid DateTime. using datetime.ParseExact in C#

a guest Mar 23rd, 2012 50 Never
  1. if (!string.IsNullOrEmpty(SessionDictionary.GetValue("UserDetails", "ExpiryDate")))
  2. {
  3.     DateTime ExpiryDate = DateTime.ParseExact(SessionDictionary.GetValue("UserDetails", "ExpiryDate"), "dd mmm yy", null);                      
  4.     strDate = sitedata.FormatDate(ExpiryDate, TridionDateFormat.ShortDate);
  5. }
  6. else
  7. {
  8.     strDate = "-";
  9. }
  10.        
  11. DateTime.ParseExact(..., "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
  12.        
  13. DateTime ExpiryDate = DateTime.ParseExact(SessionDictionary.GetValue("UserDetails", "ExpiryDate"), "dd/MM/yyyy hh:mm:ss", null)
  14.        
  15. DateTime ExpiryDate = DateTime.ParseExact(SessionDictionary.GetValue("UserDetails", "ExpiryDate"), "G", null)
RAW Paste Data
Top