Dim dt As DateTime
Dim dtUtc As DateTime
dt = DateTime.Now
dtUtc = DateTime.UtcNow
Dim ts As TimeSpan = dtUtc.Subtract(dt)
dt = dt.Add(ts)
dt = dt.AddDays(2)
dt = dt.AddSeconds(34)
Many thanksFor i=0 to 3
t=t+22 sec
if t>=60 then
'add min
elseif t>=3600 then
'add hour
end if
dt=hour:min:sec
Next
You're just making it hard for yourself by using TextBoxes. Use DateTimePickers like you should and it becomes a doddle:I am having a similar problem in a timekeeping application.
The time values are declared as:
dim
as DateTime
dim dtOut as DateTime
dim ts as TimeSpan
Times are entered in textboxes by the user andconverted to the DateTime variables
This code:
ts=dtOut.subtract(dtIn)
Results in ts = -3:00:00 when the user enters:
08:00 AM for the tme In and
08:00 PM for the time out
If the user enters (for example 8:00 AM in and 11:00 AM out ) the calculation is correct. How can I dalculatethe Timespan for a period of time statrting in the AM and ending in the PM?
Dim time As TimeSpan = Me.endTimePicker.Value.TimeOfDay.Subtract(Me.startTimePicker.Value.TimeOfDay)