  Add & Subtract Time

Discussion in 'Questions (Windows Mobile)' started by cdeane, Oct 24, 2007.

1. I need to know how to add/subtract time.
I'm creating a numpad that will display the time in increments(1:00,5:00,10:00 so on and so forth).
The user only needs to see the time he/she inputs.I can do that.But what I cant do is to so the sum.
I suppose I could convert time in to ticks but that is lost on me.

Here I have an example of what I'm working on:

(03:25-03:45=00:20)
then
(09:00+21:00=11:40)

As you see I'm using 24 hour display and I subtracted the 20min from the run time of 12 hours.

2. I think I really didn't get your problem.
You could easily use Time and TimeParse for your calculations.

After setting the preferred time format (24 hour display) with
Code:
TimeFormat("HH:mm")
you could do something like this
Code:
Label1.Text = Time(TimeParse("03:45") - TimeParse("03:25"))
wich results in Label1.Text = "00:20"

specci48

3. This is best (and easiest) thing to do to perform accurate time calculations - it's not difficult to get your head round it. Ticks are just a count of small increments of time from a defined starting time. Convert to ticks, do the sums and convert back at the end. Just read through Help->Main Help->Keywords->Time to see what can be done.

4. Ill give them a try.
Thank you very much

5. Hello!

A question about ticks, time dates...

What about the years with february with 29 days? Is this included in ticks.

Thx, kavka

6. Ticks represent 1 / 10,000,000 of a second.
When you use Date (TicksValue), leap years and regular years are considered.

7. So you think that calculation of dates and times is better to be performed with ticks than with TimeParse?

Thx

8. It is easier to convert the time string to ticks with TimeParse / DateParse and then do the calculations with the ticks values.

9. Hello!

I want to add time values togeder which are in a table (all in one column). The sum will be higher then 24 hours and I need the value in hour:minute form (345:23). How is this possible to do?

These time values are sorted by dates, I want to add togeder these time values for previous six days. Not the last six entries but the last six days.

Thx

10. Hi kavka,

Convert first the date/time to 'ticks' before adding/subtracting them.

and then convert it back to hours and minutes like...

SUM=summation of ticks

h=Int(sum/cticksperhour)
m=Int((sum Mod cticksperhour)/cticksperminute)
Msgbox(h&":"&m)

Regards,
__________________

11. Ok Rioven, I will try it this way.

Thx