Add & Subtract Time

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

  1. cdeane

    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:


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

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

  3. agraham

    agraham Expert Licensed User

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

    cdeane Member

    Ill give them a try.
    Thank you very much
  5. Erel

    Erel Administrator Staff Member Licensed User

  6. kavka

    kavka Member Licensed User


    A question about ticks, time dates...

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

    Thx, kavka
  7. Erel

    Erel Administrator Staff Member Licensed User

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

    kavka Member Licensed User

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

  9. Erel

    Erel Administrator Staff Member Licensed User

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

    kavka Member Licensed User


    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.

  11. Rioven

    Rioven Active Member Licensed 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

    m=Int((sum Mod cticksperhour)/cticksperminute)

  12. kavka

    kavka Member Licensed User

    Ok Rioven, I will try it this way.

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice