Click here to Skip to main content
15,907,910 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my code

DateTime SubmitDate = Convert.ToDateTime(txtPayrollStart.Text );

in this code come to error when it is run. date time format is dd-MM-yyyy .plz tell me what is the right format
Posted

This error occurs because the value in txtPayrollStart.Text is not a DateTime.
To check for date times, always use DateTime.TryParse[^] to ensure the value you are converting is a valid date time.
 
Share this answer
 
v2
Comments
Member 10385151 9-Aug-14 5:35am    
its not working
Abhinav S 9-Aug-14 6:22am    
Are you entering a valid date in the textbox?
Member 10385151 9-Aug-14 6:39am    
yes in dd-MM-yyyy format
Hello ,
Try this way
DateTime dt;
DateTime.TryParseExact(dateTime, 
                       "yyyy/MM/dd", 
                       CultureInfo.InvariantCulture, 
                       DateTimeStyles.None, 
                       out dt);
 
Share this answer
 

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