locked
String was not recognized as a valid DateTime RRS feed

  • Question

  • User457850011 posted

    I have a column of integers values of dates, for example 20120103 and want to convert these integers to datetime but getting an error " String was not recognized as a valid DateTime error" using the code below. Any help would be appreciated

    var today = DateTime.Now.AddDays(-1).Date;							
      var Data = (from u in Users()
                  from c in u.employees
                  from h in c.admin
    	          from s in h.teams
          where  
                (DateTime.ParseExact(s.admitInitial.ToString(), "dd-MM-yyyy HH:mm:ss", null) <= today 
              || DateTime.ParseExact(s.admitFinal.ToString(), "dd-MM-yyyy HH:mm:ss", null) <= today)
                   
                  select c).Distinct();



    Saturday, October 26, 2019 2:36 AM

Answers

  • User475983607 posted

    The best solution is fixing the database bug by converting the integer date column into a DateTime.  If you do not want to convert the type then you should use the correct data type, an integers, when filtering the table.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 26, 2019 12:00 PM

All replies

  • User475983607 posted

    The best solution is fixing the database bug by converting the integer date column into a DateTime.  If you do not want to convert the type then you should use the correct data type, an integers, when filtering the table.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 26, 2019 12:00 PM
  • User457850011 posted

    Hi 

    Thanks for your response. At  least it has given me a clue as to what to do

    Saturday, October 26, 2019 12:26 PM