Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 0.69 KB  |  hits: 12  |  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. LINQ Convert string to datetime
  2. DateMonth=convert(datetime, convert(char(6), AASI.Inv_Acctcur) + '01')
  3.        
  4. "yyyyMMdd"
  5.        
  6. SELECT convert(datetime, '20161023', 112) -- yyyymmdd
  7.        
  8. // Doing .ToArray is essential, to ensure that the
  9. // query is executed right away.
  10. string[] inMemoryCollectionStrings = (
  11.     from item in db.Items
  12.     where some_condition
  13.     select item.Inv_Acctcur).ToArray();
  14.  
  15. // This next query does the translation from string to DateTime.
  16. IEnumerable<DateTime> dates =
  17.     from value in inMemoryCollectionStrings
  18.     select DateTime.ParseExact(value, "yyyyMMdd",
  19.         CultureInfo.InvariantCulture);
  20.        
  21. DateTime.ParseExact(value, "yyyyMMdd", CultureInfo.InvariantCulture);