Conversing DateFormula to Integer

klumklum Member Posts: 102
Hi All,

I am working on Nav4.0SP3. I used search the forum already but I cannot find the exactly answer for my question...I have to apologize first if I do ask the same question..

My question is "How do converse DateFormula to Integer?"

For the example :

I have field called Duration with Dateformula DataType I need to converse this filed to be Month

Ex. If user put data = 18M I just need 18 and if user put data like this --> 1Y+6M+3D I have to converse to Month first and then converse to integer again...for get the value to compute...

I hope you understand my question...

Best Regards,
Wanvisa

Comments

  • pdjpdj Member Posts: 643
    Why do you want to extract values of the DateFormula?
    I'm quite sure that the CALCDATE function can solve your problems.
    Syntax:
    NewDate := CALCDATE(DateExpression [, Date])

    Where DateExpression can be a DateFormula, Text or Code.
    Check on-line help for further information about the function.
    Regards
    Peter
  • kinekine Member Posts: 12,562
    There is no easy way how to split the date formula into parts. Do not forget that:

    1) It is language-depending
    2) Formulas can be complex - e.g. 'CY-2M-5D+1M+1Y-2W+2D+CM' - how do you want to convert that?
    8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • matttraxmatttrax Member Posts: 2,309
    Function convert(DateFormula d)
       CurrMonth := DATE2DMY(TODAY, 2);
       CurrYear := DATE2DMY(TODAY, 3);
       NewDate := CALCDATE(TODAY, d);
       CalcMonth := DATE2DMY(NewDate, 2);
       CalcYear := DATE2DMY(NewDate, 3);
       IF CurrMonth < CalcMonth  // 01-05 to 12-06
          EXIT( (CalcMonth - CurrMonth + 1) * (CalcYear - CurrYear + 1) )
       ELSE  // 12-05 to 06-06
          EXIT( (CurrMonth - CalcMonth + 1) * (CalcYear - CurrYear) );
    

    Note: I didn't test it, just typed something out from my head, but I think it makes sense. It's at least a starting point and you can tweak it a little bit.
  • klumklum Member Posts: 102
    Thanks guys....

    I agree with you kine...so I just need some reference for explain to my consultant that we should use integer field it will be better in this case. However I will try code from matttrax that suggested to me..Thanks again :)


    Best Regards,
    Wanvisa
  • David_SingletonDavid_Singleton Member Posts: 5,479
    klum wrote:
    Hi All,

    I am working on Nav4.0SP3. I used search the forum already but I cannot find the exactly answer for my question...I have to apologize first if I do ask the same question..

    My question is "How do converse DateFormula to Integer?"

    For the example :

    I have field called Duration with Dateformula DataType I need to converse this filed to be Month

    Ex. If user put data = 18M I just need 18 and if user put data like this --> 1Y+6M+3D I have to converse to Month first and then converse to integer again...for get the value to compute...

    I hope you understand my question...

    Best Regards,
    Wanvisa

    Calcdate is a "non linear function", and as any mathematician will tell you, a non linear function can never be converted into a linear function.
    David Singleton
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Calcdate is a "non linear function", and as any mathematician will tell you, a non linear function can never be converted into a linear function.

    OK, before any "real" mathematicians catch me out, CALCDATE is a "non contiguous function" not a "non linear function", but the principle applies to both.

    Hmm maybe its both.
    David Singleton
  • DenSterDenSter Member Posts: 8,305
    what happens with '+2M+3D'? which integer will you get then?
Sign In or Register to comment.