On 11 Aug 2005 10:25:51 -0700, pmclinn wrote:
I have data stored in an array in this format:
Str(0) = "AUG"
Str(1) = "10"
Str(2) = "13:44:38" (24 Clock)
I need to re-assemble this into a valid date variable. What is the
best algorythm to do this?
Right now I'm converting AUG to an 8 and then 10 to a day and assuming
that the year is always 2005.
8/10/2005 13:44:38
There has to be a better way...?
Well, the assumption of the year is a big problem that you will need to
decide what the RIGHT thing to do is. If today were 1 Jan 2006 and you are
handed the strings above, do you *want* it to assume 2006, or 2005, or
what?
A way to assume the current year, rather than 2005, is to substitute
Year(Now) for 2005 in your existing code.
Now ... a way to turn a string into a date value when you are positive you
know the format, is the method Date.ParseExact. I ran this in the debugger
(just paused at a breakpoint in one of my own programs and typed this in
the Command Window):
? date.ParseExact("10 AUG 13:44:38","dd MMM HH:mm:ss",nothing)
#8/10/2005 1:44:38 PM#
From what I can determine, the absent year in that string is going to be
assumed to be the current year - again, that may or may not be what you
want.