Add & Subtract Time

cdeane

Member
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.
 

specci48

Well-Known Member
Licensed User
Longtime User
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
B4X:
TimeFormat("HH:mm")
you could do something like this
B4X:
Label1.Text = Time(TimeParse("03:45") - TimeParse("03:25"))
wich results in Label1.Text = "00:20"


specci48
 

agraham

Expert
Licensed User
Longtime User
I suppose I could convert time in to ticks but that is lost on me
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.
 

kavka

Member
Licensed User
Hello!

A question about ticks, time dates...

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

Thx, kavka
 

kavka

Member
Licensed User
So you think that calculation of dates and times is better to be performed with ticks than with TimeParse?

Thx
 

kavka

Member
Licensed User
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
 

Rioven

Active Member
Licensed User
Longtime User
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,
__________________
 
Top