Date time

  • Thread starter Thread starter Yosi
  • Start date Start date
Y

Yosi

Why i cann't convert date to DateTime :
System.DateTime dd= Convert.ToDateTime("27/09/2003");

How to do that , tjis one thowes an exception .

I can't find a Date class
 
Dates of that format are ambiguous. It's probably trying to parse this as
MM/dd/yyyy. Clearly this specific date is dd/MM/yyyy but the parser doesn't
try to figure that out. You can use DateTime.ParseExact, e.g.

DateTime dd = DateTime.ParseExact("27/09/2003", "dd/MM/yyyy");

See the documentation for DateTime.Parse to see some more flexible examples
of how to do this without explicitly specifying the format.
 
DateTime dd = DateTime.ParseExact
("27/09/2003", "dd/MM/yyyy");

I still get an error :
"(939): No overload for method 'ParseExact' takes '2'
arguments"
 
Back
Top