Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I execute, I get this error message.

DateTime date = DateTime.Parse(sdate);
"String is not a valid DateTime"

public ActionResult DownloadFile(string sdate)
       {
           string filecontent = string.Empty;

           //changed iFTDTLContext to IFTDTLEntities
           using (var context = new Models.AFMESEntitiesContext())
           {

               DateTime date =  DateTime.Parse(sdate);

               //changed Admits to Files
               //changed file to files
               var results = (from f in context.BlindResults
                              where f.ExtractDate.Value.Year == date.Year && f.ExtractDate.Value.Month == date.Month && f.ExtractDate.Value.Day == date.Day
                              select f).ToList();

               filecontent = CreateDelimitedData(results);
           }


What I have tried:

I tried changing the format but still get the message. Can anyone help?
Posted
Updated 19-Jun-18 4:19am
Comments
MadMyche 19-Jun-18 10:54am    
What format is it in?

1 solution

Without seeing what sdate contains, it is hard to tell.
Is it a valid DateTime? If so, what format is it in?

You really should review the documentation for the various DateTime Methods[^]
 
Share this answer
 
v2
Comments
Member 13481361 19-Jun-18 10:29am    
Format: 19-6-2018
MadMyche 19-Jun-18 10:56am    
Maybe you should try the DateTime.ParseExact() method and pass in the format

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