date conversion problem

  • Thread starter Thread starter Keith G Hicks
  • Start date Start date
K

Keith G Hicks

the "ArticleDate" variable is populated with data from an XML file. The XML
file has the date string like this: 10/24/09

I'm checking to see if it's a valid date with "IsDate" and then I need to
convert it to a yyyy-mm-dd format. But it's not working now for some reason.

Here's my code:


If IsDate(ArticleDate) Then
ArticleDate = CDate(ArticleDate).ToString("yyyy-mm-dd")
Else
ArticleErrors = ArticleErrors & ", date is not a valid date value"
End If

Using the date noted above, the code runsn but the 2nd line is converting
the date to "2009-00-24" instead of "2009-10-24"

CDate(ArticleDate) seems to be okay. When I mouse over that during
execution, the debugger shows it as #10/24/2009# like I'd expect.

What am I doing wrong?

Thanks,

Keith
 
the "ArticleDate" variable is populated with data from an XML file. The XML
file has the date string like this: 10/24/09

I'm checking to see if it's a valid date with "IsDate" and then I need to
convert it to a yyyy-mm-dd format. But it's not working now for some reason.

Here's my code:


If IsDate(ArticleDate) Then
ArticleDate = CDate(ArticleDate).ToString("yyyy-mm-dd")
Else
ArticleErrors = ArticleErrors & ", date is not a valid date value"
End If

Using the date noted above, the code runsn but the 2nd line is converting
the date to "2009-00-24" instead of "2009-10-24"

CDate(ArticleDate) seems to be okay. When I mouse over that during
execution, the debugger shows it as #10/24/2009# like I'd expect.

What am I doing wrong?

Keith:

mm is for minutes. You want MM.
 
Keith said:
the "ArticleDate" variable is populated with data from an XML file.
The XML file has the date string like this: 10/24/09

What am I doing wrong?

Apart from the mm/MM issue pointed out previously, you might want to use
DateTime.ParseExact instead of CDate so that if your program is run on a
computer with non-US date settings then it still parses it the way you want.

Andrew
 
Back
Top