Is "CDate" a bad thing to use?

  • Thread starter Thread starter Owen
  • Start date Start date
O

Owen

It doesnt seem to always pick up the sysem date format properly, for example
if I do CDate("19/07/2005") it seems to return an error, even though my
Regional Settigns are dd/MM/yyyy. It seems to ignore the Regional Settings
and expect US date format everytime.

What is the reccomended alternative to CDate?

Thanks!
Owen
 
Owen said:
It doesnt seem to always pick up the sysem date format properly, for
example if I do CDate("19/07/2005") it seems to return an error,
even though my Regional Settigns are dd/MM/yyyy. It seems to ignore
the Regional Settings and expect US date format everytime.


Maybe the seperator is set to "." instead of "/" in the regional settings?

What is the result of CDate? Is there an exception?
What is the reccomended alternative to CDate?

CDate is recommended, but you can also use Date.Parse.

Armin
 
It doesnt seem to always pick up the sysem date format properly, for example
if I do CDate("19/07/2005") it seems to return an error, even though my
Regional Settigns are dd/MM/yyyy. It seems to ignore the Regional Settings
and expect US date format everytime.

What is the reccomended alternative to CDate?

Thanks!
Owen

See the msdn help for DateTime.Parse() and DateTime.ParseExact().
 
Armin Zingler said:
Maybe the seperator is set to "." instead of "/" in the regional settings?

What is the result of CDate? Is there an exception?


Hi Armin, I get the following exception:

Cast from string "20/07/2005 09:02:33" to type 'Date' is not valid.
 
Owen said:
Hi Armin, I get the following exception:

Cast from string "20/07/2005 09:02:33" to type 'Date' is not valid.


Sorry, I can't reproduce this using your regional settings. It works here.


Armin
 
Armin Zingler said:
Sorry, I can't reproduce this using your regional settings. It works here.

Not to worry.

I fixed the problem by editing my web.config to force the culture to "en-GB"
in the <globalization> section.


Owen
 
Back
Top