Msgbox(NewDateTime("26/04/2013", "17:30",45,0),"") 'returns 28/04/2013 14:30
Msgbox(NewDateTime("26/04/2013", "17:30",-45,0),"") 'returns 24/04/2013 20:30
Sub NewDateTime(StartDate As String, StartTime As String, HrsToAdd As Int, MnsToAdd As Int ) As String
Dim OrigDateFormat,OrigTimeFormat As String
Dim NewT As Long
Dim D As Int
If HrsToAdd > 0 Then
D=Floor(HrsToAdd/24)
Else
D=Ceil(HrsToAdd/24)
End If
Dim H As Int=HrsToAdd Mod 24
OrigDateFormat=DateTime.Dateformat 'store original date format
OrigTimeFormat=DateTime.TimeFormat 'store original time format
DateTime.DateFormat="dd/MM/yyyy"
DateTime.TimeFormat="HH:mm"
NewT=DateTime.Add(DateTime.DateTimeParse(StartDate, StartTime),0,0,D)
NewT=NewT+ H*DateTime.TicksPerHour + MnsToAdd*DateTime.TicksPerMinute 'add the ticks for the hours and mns added
Return DateTime.Date(NewT) & " " & DateTime.Time(NewT)
DateTime.Dateformat=OrigDateFormat 'Revert back to original date format
DateTime.Timeformat=OrigTimeFormat 'Revert back to original time format
End Sub