How to calculate days count between two dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nishan Perera
    Active Community Member
    • Jan 2019
    • 348

    How to calculate days count between two dates

    Hi,

    I want to calculate and show the date count between tow dates in opportunities.

    Ex-
    Opportunity Life type is int

    Opportunity Life = Current date - Created date


    I have tried different thing, but nothing happen.
    Cheers!
    Nishan.
  • blueprint
    Active Community Member
    • Jan 2019
    • 223

    #2
    How and where are you doing this?

    I have a field called "age" defined in the custom clientDefs.json for a Case where I calculate the number of seconds between the current date (NOW) and the "modified_at" field:

    "age": {
    "type": "float",
    "readOnly": "true",
    "notStorable": "true",
    "view": "custom:views/fields/age-since",
    "select": "TIME_TO_SEC(TIMEDIFF(NOW(), case.modified_at))"
    }

    I'm using a custom view here to convert the seconds to hours or days (depending on number of seconds) as well as using differing markup.

    Comment

    • Maximus
      Senior Member
      • Nov 2018
      • 2731

      #3
      Hi,
      you can use this formula
      Code:
      oppAge = datetime\diff(datetime\now(), createdAt, 'days')

      Comment

      • Nishan Perera
        Active Community Member
        • Jan 2019
        • 348

        #4
        Originally posted by Maximus
        Hi,
        you can use this formula
        Code:
        oppAge = datetime\diff(datetime\now(), createdAt, 'days')
        Hi Maximus,

        your is formula working perfectly. Thank you. But one thing, i need to update this "oppAge" entity automatically each and every day. Is it possible.

        Eg -for today oppAge is 50, for tomorrow it should show as 51.
        Cheers!
        Nishan.

        Comment

        • Maximus
          Senior Member
          • Nov 2018
          • 2731

          #5
          You can't achieve such dynamic changes with formula. You can do this with a scheduled workflow.

          Comment

          • blueprint
            Active Community Member
            • Jan 2019
            • 223

            #6
            ... or like the example I provided, it updates dynamically.

            Comment

            • Nishan Perera
              Active Community Member
              • Jan 2019
              • 348

              #7
              Originally posted by blueprint
              ... or like the example I provided, it updates dynamically.
              Hi blueprint,

              Could you please show me how did you do it for case ? a complete one.

              As maximus says, via schedule workflow it working, but the thing is schedule job update modified date as well. So I need to update opp age by back-end. please help.
              Cheers!
              Nishan.

              Comment

              Working...