J
John Dann
I have a standard .Net DateTime variable to which I want to add a time
value. The catch is that the time value is only readily available as a
string as "HH:mm".
Question is whether there's a simple construction that would do this.
I'm thinking of something along the lines of:
Dim MyDate as Date = New Date(1, 1, 2007)
Dim MyNewDate as Date
Dim MyTime as String = "HH:mm"
MyNewDate = Date.Parse(MyDate.ToString("??") & " " & MyTime)
(Not sure what the ?? should be.)
or maybe
MyNewDate = Date.Parse(MyDate.ToShortDateString & " " & MyTime)
might be the best option.
I know I could deconstruct the HH:mm string into its constituent hours
and minutes integer values, but I was just curious as to whether
there's a more direct way of doing this. Another alternative might be
if there's any way of parsing a Timespan type from the time string,
but I can't spot any such method.
NB This needs to work for locales using both US and non-US date
formats, which is partly why I'm asking here, ie to get a solution
that will definitely work worldwide and not just in my current locale.
JGD
value. The catch is that the time value is only readily available as a
string as "HH:mm".
Question is whether there's a simple construction that would do this.
I'm thinking of something along the lines of:
Dim MyDate as Date = New Date(1, 1, 2007)
Dim MyNewDate as Date
Dim MyTime as String = "HH:mm"
MyNewDate = Date.Parse(MyDate.ToString("??") & " " & MyTime)
(Not sure what the ?? should be.)
or maybe
MyNewDate = Date.Parse(MyDate.ToShortDateString & " " & MyTime)
might be the best option.
I know I could deconstruct the HH:mm string into its constituent hours
and minutes integer values, but I was just curious as to whether
there's a more direct way of doing this. Another alternative might be
if there's any way of parsing a Timespan type from the time string,
but I can't spot any such method.
NB This needs to work for locales using both US and non-US date
formats, which is partly why I'm asking here, ie to get a solution
that will definitely work worldwide and not just in my current locale.
JGD