date conversion problem

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
 
D

Dennis

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.
 
A

Andrew Morton

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top