Wednesday, March 28, 2012

String was not recognized as a valid DateTime in another server

Hi guys,

I am currently facing this problem for quite some time now.

This is my codes below :

--------------------

Dim dateBetweenAsString = txtDateBetween.Text.ToString.Trim

Dim dateToAsString = txtDateTo.Text.ToString.Trim

'stored procedure is done here<blah><blah>

.Parameters.AddWithValue("@dotnet.itags.org.DateBetween", DateTime.Parse(dateBetween))

.Parameters.AddWithValue("@dotnet.itags.org.DateTo", DateTime.Parse(dateTo))

-------------------

Everything was working perfectly on my comptuer but when I tried on another server, it prompts me "String was not recognized as a valid DateTime"

I've tried conversion on both sql and asp.net but to no avail. Can someone please help?

Ryan.

Hi Ryan,

Based on my understanding, your asp.net application works fine on your local. But you get the error message above on another server when the application tries to convert the string to DateTime. If I have misunderstood you, please feel free to let me know.

Firstly, please make sure that the DateTime format matchs the DateTime format on the server.

If the formats are different, please try to use CurrentCulture's DateTimeFormat property. For example:
DateTime dt = DateTime.Parse(dateBetween, System.Threading.Tread.CurrentThread.CurrentCulture.DateTimeFormat);

Besides, you can get more information from theStandard DateTime Format Strings.

I hope this helps.


hi Hyde,
why are u usingDim dateBetweenAsString = txtDateBetween.Text.ToString.Trim

Dim dateToAsString = txtDateTo.Text.ToString.Trim, string to declare and pass as datatime,

I think you should declare both variables as datatime, and use datatimefunction to add, subtract, format or less than or greater than function provided by Thomas.

Cheers>
Dinesh.

0 comments:

Post a Comment