4
Answers

Convert.ToDateTime() not working on Server. Format Exception

Rashmi Saini

Rashmi Saini

8y
380
1
TxtPolCreatedDate.Text = Convert.ToDateTime(TxtPolCreatedDate.Text).ToString("dd/MMM/yyyy");
Its working fine on local machine but not working on server . I have also checked for the Date.Parse() and specify culture as suggested on
https://msdn.microsoft.com/en-us/library/9xk1h71t(v=vs.110).aspx.
But not working..
It gives error :  "String was not in Correct Format"
Answers (4)
0
Fabio Silva Lima

Fabio Silva Lima

NA 2.5k 156.6k 8y
I believe you cannot convert any string to datetime. A better solution is normalize that string cheking if is a Date, if is not you need to start search for some format: YYYY-MM-DD, DD.MM.YYYY, DD/MM/YYYY, MM/DD/YYYY and so on... after that convert as DateTime
0
Rashmi Saini

Rashmi Saini

NA 306 10.2k 8y

@Suvendu Shekhar Giri 

It can be in any format 
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 8y
Please provide what is the value you are getting in textbox(TxtPolCreatedDate.Text). Based on textbox value we need to write formatting. Follow below link that may help you: 
 
 http://www.c-sharpcorner.com/article/datetime-in-c-sharp/
 
http://www.c-sharpcorner.com/UploadFile/manas1/string-to-datetime-conversion-in-C-Sharp/
0
Suvendu Shekhar Giri

Suvendu Shekhar Giri

NA 7k 83.1k 8y
In which format are you giving the value to the textbox TxtPolCreatedDate.Text?
Try giving value in yyyy-MM-dd format and check.