Duration (TIME) to close of day (Midnight)

Dean_Axon
Dean_Axon Member Posts: 193
I'm trying to find the DURATION based on a time I enter (say 23:30:00) to Midnight (24:00:00 or 00:00:00 as navision Help says).

My Problem is that when I do this:

Duration := 000000T-MyTime;
(Duration := 000000T-23:30:00)
I get -23 hours and 30 minutes

How do I get the difference of 30 minutes with C/AL Code ?!?!!?!?!

Any help would be appreciated, in fact ALL help would be appreciated.
Remember: Keep it simple

Comments

  • Dakkon
    Dakkon Member Posts: 193
    You should use DateTime data types. Try something like the following:
    MidNight := CREATEDATETIME(020907D,000000T);
    myDuration := MidNight - CURRENTDATETIME;
    
    In the above example, MidNight is just a variable of DateTime. You can of course substitute the 020907D literal with a CALCDATE call or whatever value suits your needs.
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
  • kine
    kine Member Posts: 12,562
      Dur := CREATEDATETIME(020100D,0T)-CREATEDATETIME(010100D,MyTime);
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Dakkon
    Dakkon Member Posts: 193
    well sure if you want to go and optimize it to one line ;p *grin*
    I still like using meaningfull variable names for constant values :)
    Or maybe even define a function TIMETILLMIDNIGHT and drop the code there:)
    I guess we all have our individual preferences hehehehe
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
  • Dean_Axon
    Dean_Axon Member Posts: 193
    I ended up doing this...
      HourstoMidnight[1]:=235959t-inTime[1];
      HourstoMidnight[1]+=1000;
    

    Not as clean, but functional.

    Will try some of these suggestions though
    Remember: Keep it simple