I want to create a new field with the name Close Time, which indicates the time an opportunity was closed. I am unsure on how to do it. I have also found this (Making opportunity close dates work as a date time) Question, but it didn't help me much.

I am currently in the New Custom Field section where I can write my formula. And my question is on how to write the formula.
I know it should be something like "If Opportunity is closed, then get the current time."

1 Answer 1


You can follow trailhead module of how to write formula field in Salesforce:


You can also have a look at Formula fields Limits and restriction:


Now coming to your questions, You want to capture Close Time when you are closing an Opportunity, you can not do this by formula field since formula fields execute condition everytime if it meets certain criteria. You can use workflow rule to solve this problem:

Please follow below Steps:

  1. Create a custom field of type Date/Time(Do not create formula just normal custom field).

  2. From Setup, Process Automation-->WorkFlow Actions-->WorkFlow Rules(You can simply search for Workflow in Quickfind) & Click New Rule

  3. In the Object drop-down list, choose Opportunity, and click Next.

  4. In the Rule Name text box, enter relevant text.

  5. In the Evaluate the rule when a record is: field, select: created and everytime it's edited

  6. In the Rule Criteria section: Select formula and then do this:

AND( ISCHANGED(StageName), OR(TEXT(StageName) = 'Closed Won',TEXT(StageName) = 'Closed Lost'))

  1. Click Save & Next.

  2. Now let's create the field update action for this workflow rule. In the Immediate Workflow Actions area, click Add Workflow Action, and select New Field Update.

  3. In the Name text box, enter a relevant name for Field Update.

  4. In the Field to Update drop-down list, choose the new custom date/time field that you created in Step 1.

  5. Under Specify New Field Value, choose formula and then type this: NOW()

  6. Click Save.

  7. Activate the Workflow Rule.

In order to test the functionality, Goto Opportunity Record and Change the stage to Closed Won or Close Lost, you will see the result.

Let me know if it's helpful.

  • This sounds really helpful! But when I navigate to Setup and click on Create, there is no such option for "Workflow & Approvals", there is "Workflow process" and when I click on New there, the options there don't line up with what you described. Commented Apr 1, 2021 at 6:28
  • It was hidden somewhere else, but I managed to follow it. Thanks for the help! Commented Apr 1, 2021 at 6:38
  • Yes You must be using Lightning. I have updated Step 2
    – SFDCDJ
    Commented Apr 1, 2021 at 6:39
  • I have another question. Can I set my field as "read-only", or will that mess up the workflow? Commented Apr 1, 2021 at 6:40
  • You can set your field as Read only at page layout. But remember System Admin can still edit the field while other profiles could not.
    – SFDCDJ
    Commented Apr 1, 2021 at 6:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .