Convert VB6-style Date Format string to VB2005-style Date Format string?

O

\(O\)enone

In VB6, the Format() function when applied to dates used some "intelligence"
in order to handle the double-meaning of some characters. For example, the
following command:

\\\
MsgBox Format(Now, "yyyy-mm-dd hh:mm:ss")
///

....would correctly interpret the "mm" within the date part as the month, and
the other "mm" in the time part as the minute.

In VB.NET, they changed to the more predictable mechanism of using different
characters for "month" and "minute", so the above function is now:

\\\
MsgBox(Strings.Format(Now, "yyyy-MM-dd HH:mm:ss"))
///

Does anyone know of a function that will reliable translate from the old VB6
format string to the new .NET one? In other words, I'm looking for a
function for which if I pass in the string "yyyy-mm-dd hh:mm:ss", it returns
the value "yyyy-MM-dd HH:mm:ss".

Many thanks,
 
J

Joergen Bech

Actually, in VB6 it should be written as

Format$(Now, "yyyy-mm-dd hh:nn:ss")

but as you say,

Format$(Now, "yyyy-mm-dd hh:mm:ss")

works as well.

If you try out various combinations in VB6 you will find that
the only thing that will cause VB6 to interpret m or mm as minutes
is if the characters are preceded by

[<whitespace>]h[h][<whitespace>][:]

e.g.

"h:m" or "h:mm" or "hh:m" or "hh:mm" (with or without the ":") will
work, but if you just want minutes and seconds, you cannot write
"mm:ss" - then you have to write "nn:ss".

If this condition is not satisfied, m[m] means month.

Regards,

Joergen Bech
 
O

\(O\)enone

Joergen Bech @ post1.tele.dk> said:
If you try out various combinations in VB6 you will find that
the only thing that will cause VB6 to interpret m or mm as minutes
is if the characters are preceded by

[<whitespace>]h[h][<whitespace>][:]

e.g.

"h:m" or "h:mm" or "hh:m" or "hh:mm" (with or without the ":") will
work, but if you just want minutes and seconds, you cannot write
"mm:ss" - then you have to write "nn:ss".

If this condition is not satisfied, m[m] means month.

That's brilliant Joergen, that should provide everything that I need to
write a conversion function.

Many thanks for your help!
 

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