On 2010-04-29, Saga <(E-Mail Removed)> wrote:
> I need to add the time a a date, specifically, the current date.
> This seemed easy enough, but I found that thi wasn't so.
>
> As in input I get 3 or 4 digits representing the date. Valid
> input string are:
>
> "0344", "1102", "456"
>
> The minutes are always 2 digits, but the hour can be either
> 1 or 2 digits.
>
> What I did was first come up with a function to normalize
> the input string which formats it hh:mm:
>
If you don't use a 24 hour clock here (HHmm), then your not ever going to be
able to distinguish between am and pm with out more information

. So, here
is what I have assuming 24 hour clock...
Option Explicit On
Option Strict On
Module Module1
Sub Main()
Dim str() As String = {"1146", "0344", "442", "601", "1302", "2359"}
Dim fmt As String = "MM/dd/yyyy HHmm"
For Each t As String In str
Dim cur As String = Date.Today.ToString("MM/dd/yyyy ") & String.Format("{0,4}", t).Replace(" ", "0")
Dim d As Date
Date.TryParseExact(cur, fmt, Nothing, Globalization.DateTimeStyles.None, d)
Console.WriteLine(d)
Next
End Sub
End Module
--
Tom Shelton