Convert C# DateTime To VB6 Date

I have an XML node with text of '0001-01-01T00:00:00' that represents a .NET DateTime property. I can load this into VB6 using DOM, but how do I convert this into a VB6 Date variable?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

myDate = CDate(Replace("2009-11-23T23:34:45", "T", " "))

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BrianGilbertAuthor Commented:
I have this already, looking for a more robust solution - is there one out there?
I don't think you'll find a method which is more robust than the built in function designed to convert strings to dates? I have used CDate extensively for many years and in many applications and as far as I know it has always been ultra reliable. Do you have an example of a specific instance where that method hasn't worked for you?

The only thing I can think of is that the character separating the date and time in string isn't always a "T". Perhaps a better method would be to replace that character with a space, whatever it is;

s = sXMLNodeDate
Mid(s, 11, 1) = " "
myDate = CDate(s)
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Patrick MatthewsCommented:
BrianGilbert said:
>>I have this already, looking for a more robust solution - is there one out there?

I second Antagony1960's suggestion: that method is very, very robust, and will *always* work as long as the
data passed to the expression comes as yyyy-mm-ddThh:nn:ss.

The only way that can fail is if the XML content does not follow that format, or if you try to pass a date that
is outside VB6's acceptable date ranges.  SInce VB6 accepts anything from the year 100 through the year
9999, I find that very unlikely indeed  :)
Patrick MatthewsCommented:

BTW, no points please for my post.  I was realy only backing up Antagony1960, not offering anything new.


BrianGilbertAuthor Commented:
What is the date - T - time format? IS it .NET specific of XML?
It's produced by the .Net SortableDateTimePattern format pattern, which would be specified as "s" in the DateTime object's ToString method; like so:

myDT.ToString("s", myCulture)

If that "s" were changed to a "u" it would format the output in UniversalSortableDateTimePattern, which uses a space rather than a "T" and VB's CDate function would work directly on the string, like so: CDate(myXMLNodeDate)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.