DateTime.ParseExact Equivalent for VB6?
<p>Does anyone know if there's an <em>actual</em> equivalent method in VB6 for .NET's <code>DateTime.ParseExact()</code> method?  I've tried using <code>DateSerial()</code>, <code>IsDate()</code> and <code>CDate()</code>, but, due to all of VB6's "helpfulness", I'm coming up with some unexpected results.</p>

<p>To be more specific, I'm trying to parse a text string from user input to validate whether or not it's an actual date.  As an example, I'll be using the date <code>8/25/16</code>.  The usual expected input may or may not have delimiters between the month, day and year, so it may be entered as <code>82516</code>.</p>

<p>Here's a sample of the code that's not working as intended (the value of <code>82516</code> is stored in the <code>TempStr</code> variable):</p>

<pre><code>If IsDate(Format(TempStr, "#/##/##")) And IsDate(Format(TempStr, "##/#/##")) Then
    TempDate = #12:00:00 AM#
ElseIf IsDate(Format(TempStr, "#/##/##")) Then
    TempDate = CDate(Format(Tempstr, "#/##/##"))
ElseIf IsDate(Format(TempStr, "##/#/##")) Then
    TempDate = CDate(Format(TempStr, "##/#/##"))
End If
</code></pre>

<p>Using the stated value, the first condition triggers.  Knowing how it works, I understand why it's happening (it's "rearranging" the month, day and year to try to match a valid date), but I'm really trying to get it to parse the date in a specific order.  I know that .NET's <code>DateTime.ParseExact()</code> method would get me there, but I have to do this in VB6 (maintaining some legacy code).</p>

<p>I tried using <code>DateSerial()</code>:</p>

<pre><code>If DateSerial(CInt(Right(TempStr, 2)), CInt(Left(TempStr, 1)), CInt(Mid(TempStr, 2, 2))) &gt; #12:00:00 AM# Then
    If DateSerial(CInt(Right(TempStr, 2)), CInt(Left(TempStr, 2)), CInt(Mid(TempStr, 3, 1))) &gt; #12:00:00 AM# Then
        TempDate = #12:00:00 AM#
    Else
        TempDate = DateSerial(CInt(Right(TempStr, 2)), CInt(Left(TempStr, 1)), CInt(Mid(TempStr, 2, 2)))
    End If
Else
    If DateSerial(CInt(Right(TempStr, 2)), CInt(Left(TempStr, 2)), CInt(Mid(TempStr, 3, 1))) &gt; #12:00:00 AM# Then
        TempDate = DateSerial(CInt(Right(TempStr, 2)), CInt(Left(TempStr, 2)), CInt(Mid(TempStr, 3, 1)))
    Else
        TempDate = #12:00:00 AM#
    End If
End If
</code></pre>

<p>But that also comes along with an automatic correction if the values for any of the parameters fall outside of the acceptable ranges.</p>

<p>I also tried the following variation of the above code:</p>

<pre><code>If IsDate(Format(TempStr, "m/dd/yy")) And IsDate(Format(TempStr, "mm/d/yy")) Then
...
</code></pre>

<p>But the first test results in an <em>entirely</em> different value of <code>3/12/26</code>, which is WAY off from the original input.</p>

<p>Is there any way to accurately emulate the .NET <code>DateTime.ParseExact()</code> method in VB6, or am I just going to have to toss these types of user input values out as invalid/ambiguous?</p>