My date conversion from textbox is working in localhost but not in online server in asp.net c#

StackOverflow https://stackoverflow.com/questions/22574130

Вопрос

my code for converting date is given below,

        DateTime dat1 = Convert.ToDateTime(txtDOB.Text);
        string date2 = dat1.ToString("MM/dd/yyyy");

i got error like this,

Exception Details: System.FormatException: String was not recognized as a valid DateTime.

Source Error:

Line 68: DateTime dat1 = Convert.ToDateTime(txtDOB.Text);

how can recover this,plzzzz help...

Это было полезно?

Решение

I guess you should Use DateTime.ParseExact with the format "MM/dd/yyyy"

DateTime.ParseExact(txtDOB.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture)
                        .ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);

you can go though the below link for more information

http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top