how to calculate times in c/al ? (opened again)

Manuel_A.Manuel_A. Member Posts: 22
How can i calculate times in c/al ?

For example:

sum:=endtime-starttime;

All of them are set as "Time" but i get an convert Error. time:=integer.

regards
Manuel A.

Comments

  • s.delikostovs.delikostov Member Posts: 32
    sum is integer - difference between the two times in miliseconds
    Stamen Delikostov
    Navision Solution Developer
    Intelligent Systems Bulgaria
  • Manuel_A.Manuel_A. Member Posts: 22
    no, i declared sum also as time. Its a value in a table i created.
  • s.delikostovs.delikostov Member Posts: 32
    What you think is the differnece between two times?
    Stamen Delikostov
    Navision Solution Developer
    Intelligent Systems Bulgaria
  • Manuel_A.Manuel_A. Member Posts: 22
    Starttime= 08:00
    Endtime = 12:00
    Break = 00:30

    The Difference is:

    sum=Endtime-Startime-Break

    sum=12:00-08:00-00:30

    sum=3:30 (hours)

    thats what i want to create
  • SteveOSteveO Member Posts: 164
    edited 2005-04-20
    s.delikostov is correct. You should make your field sum into an Integer type.

    As s.delikostov, said Navision calculates the difference between 2 times as milliseconds.

    You can then convert the milliseconds into hours.

    You shouldn't have Break as a time field though. You should make a new field called "Break in Minutes" (or something like that).

    Then work out the difference between Start Time and End Time. Convert that to minutes. Subtract "Break in Minutes", this will return total time taken in minutes. You can then convert that to hours if that is what you need.

    -- EDIT --
    When converting from Seconds to minutes (and to hours) you will need to use a decimal field as you will be incurring decimals.

    Eg: In your example, when you eventually reach your answer it will be 3.5 (hours), therefore you will need a decimal.
    This isn't a signature, I type this at the bottom of every message
  • Manuel_A.Manuel_A. Member Posts: 22
    ok, i set sum to integer, now it works.

    Which command do i have to use to convert it to hours?
  • s.delikostovs.delikostov Member Posts: 32
    sum=12:00-08:00
    sum=14400000
    hours=14400000/3600000=4
    Stamen Delikostov
    Navision Solution Developer
    Intelligent Systems Bulgaria
  • Manuel_A.Manuel_A. Member Posts: 22
    of course....just have to divide it... :lol::wink:

    thank you
  • Manuel_A.Manuel_A. Member Posts: 22
    edited 2005-04-20
    its me again....


    how can i subtract the "break" too ? I cant subtract 3 values only 2 like you described.
  • s.delikostovs.delikostov Member Posts: 32
    How you calculate break time?
    If it's 12:30-12:00 - this is 0.5 hours

    if you enter 0:30 - this is not correct, better way is to enter it in a decimal - 0,5
    Stamen Delikostov
    Navision Solution Developer
    Intelligent Systems Bulgaria
  • kinekine Member Posts: 12,562
    do not forget new type "Duration" which is in ms but to user shows something as "3 hours 5 minutes"....
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.