Date Calculations

IdlenessIdleness Member Posts: 46
I'm sorry, I know it'll be here somewhere and I'm sure it's very simple but I cannot find it.

How do I add variable hours to a variable date, i.e 01/01/2009:0000 + 27hrs = 02/01/2009:0300

Thanks

Answers

  • ara3nara3n Member Posts: 9,256
    edited 2009-09-28
    Do you want to round up or Down?

    Date + integer =

    //round Down
    New Date := Date + DIV(Hours/24);



    Round UP

    Remainder := Hours MOD(24);

    if Remainder <> 0 then
    Remainder := 1;

    New Date := Date + (Hours DIV 24) + Remainder) ;
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • IdlenessIdleness Member Posts: 46
    Thanks and sorry I get an error when I try that.

    Should it be

    MyDate = 01/01/2009
    Hours = 27

    New Date := MyDate + DIV(27/24);
  • ara3nara3n Member Posts: 9,256
    Idleness wrote:
    Thanks and sorry I get an error when I try that.

    Should it be

    MyDate = 01/01/2009
    Hours = 27

    New Date := MyDate + DIV(27/24);

    New Date := MyDate + (27 DIV 24);
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • IdlenessIdleness Member Posts: 46
    Thank you sir, that has been giving me the hump for a fair while :thumbsup:
  • ara3nara3n Member Posts: 9,256
    You are welcome.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.