S
Saga
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:
private function sSetTime(byval strTime as string) as integer
strTime = strTime.ToString("D4")
Return strTime.Substring(0, 2) & ":" & strTime.Substring(2, 2)
end function
Next is my date variable where I am going to keep the date
and time:
dim dteEnd as date = date.today()
dim strT as string = "345" 'For example
Now I add the time:
dteEnd = dteEnd.AddHours(
Convert.ToDouble(sSetTime(strT.Split(":".ToCharArray()).GetValue(0).ToString()))
)
And add the minutes
dteEnd = dteEnd.AddMinutes(
Convert.ToDouble(sSetTime(strT.Split(":".ToCharArray()).GetValue(1).ToString()))
)
Is there a better way to do this? <g>
Thanks, Saga
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:
private function sSetTime(byval strTime as string) as integer
strTime = strTime.ToString("D4")
Return strTime.Substring(0, 2) & ":" & strTime.Substring(2, 2)
end function
Next is my date variable where I am going to keep the date
and time:
dim dteEnd as date = date.today()
dim strT as string = "345" 'For example
Now I add the time:
dteEnd = dteEnd.AddHours(
Convert.ToDouble(sSetTime(strT.Split(":".ToCharArray()).GetValue(0).ToString()))
)
And add the minutes
dteEnd = dteEnd.AddMinutes(
Convert.ToDouble(sSetTime(strT.Split(":".ToCharArray()).GetValue(1).ToString()))
)
Is there a better way to do this? <g>
Thanks, Saga