Click here to Skip to main content
15,886,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi every one i got this type of error in Windows Application.
when i try to insert or handle any operation in Date ... its turn to error..
how to get a format string of Date:
following way to handle the date:
1. MM/dd/yyyy
2.dd/MM/yyyy.
how to avoid this type error..based on System Date Format.. some system has MM/dd/yyyy and some other have dd/MM/yyyy how to handle common date format for all this application..

Failed to convert parameter value from a String to a DateTime.
above is my error.
Posted

check your system time format

for example :
my system time format is 20/Dec/2013 that means dd/MMM/yyyy

C#
DateTime dtime = DateTime.Parse(DateTime.Now.ToShortDateString());
                   string Sdtime = dtime.ToString("dd/MMM/yyyy");


and when insert date into table you convert the string to datetime format


Note

table column field must have "date" datatype
 
Share this answer
 
Comments
srigates 20-Dec-13 5:00am    
i am using Datetime2(7) data type
hi Try like this. It might help you..


C#
// MM/dd/yyyy
       var valueFormat1 = DateTime.ParseExact("12/30/2013", "MM/dd/yyyy", CultureInfo.InvariantCulture);

       // dd/MM/yyyy.
       var valueFormat2 = DateTime.ParseExact("30/12/2013", "dd/MM/yyyy", CultureInfo.InvariantCulture);
 
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