2

I'm facing problem while conversion of date

if I used -- Date.parse("28/01/2011") it gives me error as

"String was not recognized as a valid DateTime."

so then I modify above code as -- CDate("28/01/2011") it gives me error as

"Cast from string "28/01/2011" to type 'Date' is not valid."

I used convert.todatetime also date.parseexact but nothing is working...

I'm using VS2003 in asp.net1.1 with vb.net

Cœur
  • 37,241
  • 25
  • 195
  • 267
Amit Patil
  • 1,893
  • 4
  • 19
  • 23

1 Answers1

3

Probably Parse is using InvariantCulture date format "MM/dd/yyyy". Maybe you can try with

DateTime.ParseExact("28/01/2011", "dd/MM/yyyy", CultureInfo.InvariantCulture)

or passing a correct culture on Parse, like spanish that has date format dd/MM/yyyy

Date.Parse("28/01/2011", new CultureInfo("es-ES", true));

Write from memory, maybe is not accurate

Elph
  • 1,594
  • 1
  • 15
  • 20