Format error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a web application that when run on my local host generates the error:
Exception Details: System.InvalidCastException: Cast from string "06/17/2004" to type 'Date' is not valid.
This is the line that generates the error:
dtbOpenDate.xDate = Now.ToString("MM/dd/yyyy")

The app runs successfully on many other machines including a server which hosts it, therefore the problem is specific to my computer. If I change the format to "dd/MM/yyyy" and recompile the dll my computer, it runs it successfully. Is there a setting somewhere that would influence this (I have changed the short date format within regional settings but it makes no difference).

Thanks for any help you may have,
 
Hi Sheldon,

What I don't get, is why you are generating a date, converting it to a
string, and then casting it back to a date again.

It is clear from the error message that the dtbOpenDate.xDate field is of
type Date.

Now is also of type Date.

Why not just assign:
dtbOpenDate.xDate = Now

If you don't want the time component, then you can do this:

dtbOpenDate.xDate = Today

HTH,

--- Nick


Sheldon said:
Hi,
I have a web application that when run on my local host generates the error:
Exception Details: System.InvalidCastException: Cast from string
"06/17/2004" to type 'Date' is not valid.
This is the line that generates the error:
dtbOpenDate.xDate = Now.ToString("MM/dd/yyyy")

The app runs successfully on many other machines including a server which
hosts it, therefore the problem is specific to my computer. If I change the
format to "dd/MM/yyyy" and recompile the dll my computer, it runs it
successfully. Is there a setting somewhere that would influence this (I have
changed the short date format within regional settings but it makes no
difference).
 
Back
Top