function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Priyanka85Priyanka85 

Formula Field

Create a formula field that calculates the Age in hours of the case that is displayed on the case page layout. The age of the case is defined as the difference in hours between the Date/Time opened and date/time closed for the case. If the case is still open, the age should calculate the difference between case creation and the current date/time. If the case is closed, the age should calculate the difference between the case closed date/time and the case created date/time. 

For eg: 1.5 hours if the case has been opened for an hour and a half.

 

Any suggestions???

Best Answer chosen by Admin (Salesforce Developers) 
steve456steve456

IF( ClosedDate!=null, (ClosedDate - CreatedDate)*24 ,(DATETIMEVALUE(Today())-CreatedDate)*24)

All Answers

Jake GmerekJake Gmerek

if( isNULL(CloseDate), (Now() -  CreatedDate)*24, (Now() - CloseDate)*24)

 

You may have to change the field names to fit your org, but the idea is there.  Let me know if you have any questions.

steve456steve456

IF( ClosedDate!=null, (ClosedDate - CreatedDate)*24 ,(DATETIMEVALUE(Today())-CreatedDate)*24)

This was selected as the best answer
Priyanka85Priyanka85

I have made Number type formula field with decimal value =1 and formula is

IF( IsClosed, (ClosedDate - CreatedDate)*24, (NOW() - CreatedDate)*24 )

but its not working.

steve456steve456

give decimal value =2 .It is working for me

 

 

Screen of mine

 



Case OwnerStatus
New
Case Number
00001031
Priority
Medium
Contact NameCase Origin
Phone
Account Name
SteveUndo
  
Contact Phone
 
  
Contact Email
 
  
Type
 
  
Case Reason
 
  
Age
112.82
  
Date/Time Opened
11/9/2011 10:25 PM
Date/Time Closed
 
Product
 
Potential Liability
 
SLA Violation
 

 

Priyanka85Priyanka85

I want to calculate the age in hours.. so i multipiled it with 24 but then it is showing some wired data..

Refer below screen

 

   
Case OwnerStatus
New
Case Number
00001034Escalated
Priority
Medium
Contact Name
 
Contact Phone
 
Account Name
 
Contact Email
 
Type
 
Case Origin
Phone
Case Reason
 
  
Age
2.94
  
Date/Time Opened
3/2/2012 11:03 AM
Date/Time Closed
 
Product
 
Engineering Req Number
 
Potential Liability
 
SLA Violation
 
Created By
Priyanka Saxena, 3/2/2012 11:03 AM
Last Modified By
Priyanka Saxena, 3/2/2012 11:03 AM
Subject
Testing for age
Description
 
Custom Links
Up-sell / Cross-sell Opportunity 
steve456steve456

did u apply my formula.You applying some different formula

 

 

Jus copy paste it .U will get it

 

IF( ClosedDate!=null, ClosedDate - CreatedDate ,DATETIMEVALUE(Today())-CreatedDate)

 

 

Priyanka85Priyanka85

As per your formula, output is:

 

Case OwnerStatus
New
Case Number
00001034Escalated
Priority
Medium
Contact Name
 
Contact Phone
 
Account Name
 
Contact Email
 
Type
 
Case Origin
Phone
Case Reason
 
  
Age
-0.79
  
Date/Time Opened
3/2/2012 11:03 AM
Date/Time Closed
 
Product
 
Engineering Req Number
 
Potential Liability
 
SLA Violation
 
Created By
Priyanka Saxena, 3/2/2012 11:03 AM
Last Modified By
Priyanka Saxena, 3/2/2012 11:03 AM
Subject
Testing for age
Description
 
Custom Links
Up-sell / Cross-sell Opportunity
steve456steve456

first try by giving both dates.

 

 

Else try this

 

IF( ClosedDate!=null, ClosedDate - CreatedDate ,ABS(DATETIMEVALUE(Today())-CreatedDate))

 

Priyanka85Priyanka85

tried :(

 

Case OwnerStatus
Closed
Case Number
00001034
Priority
Medium
Contact Name
 
Contact Phone
 
Account Name
 
Contact Email
 
Type
 
Case Origin
Phone
Case Reason
Equipment Complexity
  
Age
-0.79
  
Date/Time Opened
3/2/2012 11:03 AM
Date/Time Closed
3/2/2012 2:32 PM
Product
 
Engineering Req Number
 
Potential Liability
 
SLA Violation
 
Created By
Priyanka Saxena, 3/2/2012 11:03 AM
Last Modified By
Priyanka Saxena, 3/2/2012 2:32 PM
Subject
Testing for age
Description
 
Custom Links
Up-sell / Cross-sell Opportunity 
steve456steve456

IF( ClosedDate!=null, ClosedDate - CreatedDate ,ABS(DATETIMEVALUE(Today())-CreatedDate))

 

Priyanka85Priyanka85

for eg:  age= 1.5 hours if the case has been opened for an hour and a half.

Priyanka85Priyanka85

Age should be 3.5hours... that is what i want 

 

but it is showing 0.79 

 

Case OwnerStatus
Closed
Case Number
00001034
Priority
Medium
Contact Name
 
Contact Phone
 
Account Name
 
Contact Email
 
Type
 
Case Origin
Phone
Case Reason
Equipment Complexity
  
Age
0.79
  
Date/Time Opened
3/2/2012 11:03 AM
Date/Time Closed
3/2/2012 2:32 PM
Product
 
Engineering Req Number
 
Potential Liability
 
SLA Violation
 
Created By
Priyanka Saxena, 3/2/2012 11:03 AM
Last Modified By
Priyanka Saxena, 3/2/2012 2:32 PM
Subject
Testing for age
Description
 
Custom Links
Up-sell / Cross-sell Opportunity