• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1070
  • Last Modified:

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?
0
BrianGilbert
Asked:
BrianGilbert
  • 3
  • 2
  • 2
1 Solution
 
Antagony1960Commented:
myDate = CDate(Replace("2009-11-23T23:34:45", "T", " "))
0
 
BrianGilbertAuthor Commented:
I have this already, looking for a more robust solution - is there one out there?
0
 
Antagony1960Commented:
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)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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  :)
0
 
Patrick MatthewsCommented:
BrianGilbert,

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

Regards,

Patrick
0
 
BrianGilbertAuthor Commented:
What is the date - T - time format? IS it .NET specific of XML?
0
 
Antagony1960Commented:
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)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now