Announcement

Collapse
No announcement yet.

how to configure formula for date format "Quartal"?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to configure formula for date format "Quartal"?

    Advanced Pack 2.5.14
    EspoCRM Version 5.9.3

    Hello!

    I am building a custom entity where I need a "quarterly" date format.

    So if the record has a date field 25.02.2020, there shall be a second date field which is autofilled with "1. Quartal 2020"

    I think that this feature should be realised with a formula in the custom entity. But I am not good enough in formulas...

    something like:

    if field "date" is between 01.01.2020 and 30.03.2020 then field "quartal" is "1. Quartal 2020"
    and
    if field "date" is between 01.04.2020 and 30.06.2020 then field "quartal" is "2. Quartal 2020"
    and
    if field "date" is between 01.07.2020 and 30.09.2020 then field "quartal" is "3. Quartal 2020"
    and
    if field "date" is between 01.10.2020 and 31.12.2020 then field "quartal" is "4. Quartal 2020"

    How can this be formulated in a correct working way?

    Thank you!

  • #2
    Hi,

    You can divide a month number by 4, floor it then add 1.

    Code:
    $quarter = number\floor(
      datetime\month(
        entity\attribute('dateFieldName')
      ) / 4
    ) + 1;
    Last edited by yuri; 09-16-2020, 08:53 AM.

    Comment


    • yuri
      yuri commented
      Editing a comment
      A forgot division. Edited the formula above.

  • #3
    Hello yurikuzn!

    appreciate your suggestion of a code!

    So what I am doing:

    Code:
    $quartal = number\floor(
    datetime\month(
    EigenkontrolleBrandschutztueren\attribute('datum')
    )
    ) + 1;


    EigenkontrolleBrandschutztueren = custom entity
    quartal = vachar field in entity EigenkontrolleBrandschutztueren
    datum = date field in entity EigenkontrolleBrandschutztueren where the user enters the date

    I dont know what in this case attribute is, I took the field name again "quartal"

    Unfortunately does not work!
    Last edited by gustavgraz; 09-16-2020, 08:22 AM.

    Comment


    • #4
      Hi gustav,
      in formula 'entity\attribute()' you don't need to replace 'entity' with 'EigenkontrolleBrandschutztueren'. It is constant value, so it should be as in the Yuri's example.
      Also, replace '$quartal' with 'quartal' in ypur formula
      Last edited by Maximus; 09-16-2020, 08:45 AM.

      Comment


      • #5
        Code:
        
        $quarter = number\floor(
          datetime\month(
            entity\attribute('datum')
          ) / 4
        ) + 1;
        
        $quarterString = string\concatenate(
          $quarter,
          '. Quartal ',
          datetime\year(
            entity\attribute('datum')
          )
        );
        
        entity\setAttribute('quartal', $quarterString);
        Last edited by yuri; 09-16-2020, 08:59 AM.

        Comment


        • #6
          Hi Maximus!

          great advice, now it works as a first step.


          The output in field "quartal" is for example "3".

          I need "3. Quartal 2020"

          So now I added string\concatenate in this way:

          quartal = string\concatenate
          (number\floor(
          datetime\month(
          entity\attribute('datum')
          ) / 4
          ) + 1,'. Quartal ','year');

          The result:
          "3. Quartal year"

          I need "3. Quartal 2020"

          Is there a way to do it?

          Thank you!

          Comment


          • yuri
            yuri commented
            Editing a comment
            Check my post above.

        • #7
          Hi yurikuzn!

          Now it works, thanks so much!

          Comment


          • #8
            hello,

            Thank you so much for sharing this helpful information, it helped me alot

            Thanks and regards. 9apps cartoonhd
            Last edited by bansalrehana; 09-30-2020, 08:36 AM.

            Comment

            Working...
            X