DateTime difference

SeaMasterSeaMaster Member Posts: 5
edited 2004-05-27 in Navision Attain
Hi,

I have a problem in Navision 3.10.
Say we have 4 variables:
Date1 - date someone enter the room
Time1 - time someone enter the room
Date2 - date someone exit the room
Time2 - time someone exit the room

I want to calculate the difference between Date1, Time1 and Date2, Time2.

The result could be something like this:
1 day 2 hours 12 minutes 12 sec.

I can't use the DateTime variable and CREATEDATETIME function
because it is not supported in Navision 3.10.

How do I do this.

Thanks in advance.

Comments

  • WarfoxWarfox Member Posts: 53
    edited 2004-05-26
    why dont u use this little code:
    duration := createdatetime(Date2,Time2) - createdatetime(Date1,Time1);
    
  • WarfoxWarfox Member Posts: 53
    oh sorry i saw it too late, heres a code without the dattime datatype and function:
    duration := (date2 - date1) * 86400000;
    duration := duration + (time2 - time1);
    

    Greez Warfox
  • SeaMasterSeaMaster Member Posts: 5
    What kind of datatype should Duration variable be. I get a strange number.
  • RobertMoRobertMo Member Posts: 484
    integer (if you don't have duration)
               ®obi           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • RobertMoRobertMo Member Posts: 484
    and the result is in miliseconds... so you have some excercise to do your formating...
               ®obi           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • WarfoxWarfox Member Posts: 53
    No the result will be in days because i multiply by 86400000.

    86400000 = 24(hours) * 60(minutes) * 60(seconds) * 1000(miliseconds)
  • RobertMoRobertMo Member Posts: 484
    well, to be exact:
    date2 - date1 returns integer representing days. after multiplying with 86400000, result is integer representing miliseconds. :wink:
    time2 -time1 returns integer representing milisecond.
    so at the end we have difference in miliseconds.
               ®obi           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • WarfoxWarfox Member Posts: 53
    Thats, right but only with an integer, with the duration data type the return of Time2 -Time1 will be in hours, i don´t know why, but it is so :shock:
  • RobertMoRobertMo Member Posts: 484
    Warfox wrote:
    with the duration data type the return of Time2 -Time1 will be in hours,
    :shock: always something new... so much about consitency
               ®obi           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Sign In or Register to comment.