Want more features on Pastebin? Sign Up, it's FREE!
Guest

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

By: a guest on Mar 23rd, 2012  |  syntax: None  |  size: 0.65 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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)
clone this paste RAW Paste Data