How sum Dateformula fields - Another question!!

LeroyLeroy Member Posts: 199
Hello again, I'm doing operations with dates and, for example, I've two Dateformula fields. I've created a Dateformula variable and I want that it shows the sum of the other two dataformula fields, but I can't. I put:

prob:=((FORMAT("Field1"))+(FORMAT("Field2")));

Field1 is 3D
Field2 is 4D

But the result is that prob shows 3D4D, it should be the sum of that days, 8D. How can I do that?.
Thanks in advance.

Comments

  • David_SingletonDavid_Singleton Member Posts: 5,479
    Leroy wrote:
    Hello again, I'm doing operations with dates and, for example, I've two Dateformula fields. I've created a Dateformula variable and I want that it shows the sum of the other two dataformula fields, but I can't. I put:

    prob:=((FORMAT("Field1"))+(FORMAT("Field2")));

    Field1 is 3D
    Field2 is 4D

    But the result is that prob shows 3D4D, it should be the sum of that days, 8D. How can I do that?.
    Thanks in advance.

    You need to do it insteps.
    Date1 := CALCDATE("Field1",Startdate);
    Date2 := CALCDATE("Field2",Date2);
    

    You can try adding etc. but always you wil find an exception that will not work.

    CalcDate is what is know in Mathematics as a non continuous function , and thus does not have an inverse. In mathematics this limits what you can and can't do with it. I have seen such things as:
    evaluate(NewDateForm,format('%1+%2',Field1,Field2));
    


    But at some stage it will fail and you will not find out until someone shows that the report is wrong.
    David Singleton
  • LeroyLeroy Member Posts: 199
    Ok; thanks for help and information; I'll try it.
    Thank you very much.
  • LeroyLeroy Member Posts: 199
    Hello again; I've prove it and it works well, thank you!!!, but, if I want to subtraction it?, I mean, I've put for example:

    prob:=CALCDATE("field1","field2");

    And it sums correctly, field1 is a Dateformula field and field2 is a Date field, the prob variable is also a Date field. If field1 i 3D and field2 is 30/01/09 it shows me 2/02/09 that is correct, but if I want to subtraction it, it should show 27/01/09. How I can do it?.

    Thanks for help in advance.
  • kinekine Member Posts: 12,562
    And what you will do with e.g. formulas like '<-CM-1D>' and e.g. '<+CM+2M>'??? You cannot just work with the formulas like with numbers. You will get different results and + and - is not commutable in this "calculation".
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • LeroyLeroy Member Posts: 199
    Thanks for reply. In my case always will be in "days". But, if it is not possible by this way, do you know if there is another way to do it?, I need to subtraction this.
    Many thanks in advance.
  • kinekine Member Posts: 12,562
    Than it is better to collect just "number of days" from the user instead the dataformula and construct the formula through something like:
    MyDate := CALCDATE('<'+FORMAT(NoOfDays1-NoOfDays2)+'D>',FromDate);
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • LeroyLeroy Member Posts: 199
    Thanks for reply. What is "FromDate " please?.
    Thanks.
  • kinekine Member Posts: 12,562
    It is some date from which you want to calc the target date when you know how many days you want to subtract or add. E.g. TODAY, Document Date etc.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • LeroyLeroy Member Posts: 199
    Ok, thanks for reply. I'll try it.
    Thanks you very much for help.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Leroy wrote:
    Thanks for reply. In my case always will be in "days". But, if it is not possible by this way, do you know if there is another way to do it?, I need to subtraction this.
    Many thanks in advance.

    Did you read y reply above?
    David Singleton
  • Mark_SmartMark_Smart Member Posts: 16
    Hello 2009. I'm ashamed to say that I have just completed writing such a function to add 2 dateformulas together. A solid 2 and a half pages of code and half a day of creative messy string parsing for the world shatteringly important cosmetic effect of merging two date formulas instead of just adding simple form (eg +5D, -1W) to the end.

    Currently the only way in testing I can break it is when the combined string exceeds the dateformula maximum length of 32, which is apparently a thing.

    Pretty sure that no one is going to ask me for a copy of the code, which should stand as a testament to the futility of such a request.
  • Mark_SmartMark_Smart Member Posts: 16
    Oh, and no, my function will not intuitively handle operators without integers.
  • Mark_SmartMark_Smart Member Posts: 16
    Hello 2009. I'm ashamed to say that I have just completed writing such a function to add 2 dateformulas together. A solid 2 and a half pages of code and half a day of creative messy string parsing for the world shatteringly important cosmetic effect of merging two date formulas instead of just adding simple form (eg +5D, -1W) to the end.

    Currently the only way in testing I can break it is when the combined string exceeds the dateformula maximum length of 32, which is apparently a thing.

    Pretty sure that no one is going to ask me for a copy of the code, which should stand as a testament to the futility of such a request.
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    What for? What's the purpose - if the date can be calculated in 2 steps in 2 separate lines of code? If this is your hobby then that's OK, but I'd be personally p***ed off as your employer, or your customer if you try to charge me for someting like this
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Mark_SmartMark_Smart Member Posts: 16
    What for? What's the purpose - if the date can be calculated in 2 steps in 2 separate lines of code? If this is your hobby then that's OK, but I'd be personally p***ed off as your employer, or your customer if you try to charge me for someting like this

    Oh, the customer was quite adamant. I told them and the consultant no many times.
Sign In or Register to comment.