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
ArunaAruna 

creating a view on contact within the past two hours of the current time

Hi Guys,

 

I have requirement, I need to create a view on Contact  within the past two hours of the current time .

 

I think this cannot be done using  based on currentdate, because our call center is open 24 hours. so If a Contact is created at 11pm on tuesday then the view would display the record up untill 1 am on wednesday.

 

can any one suggest me on this how to create the viwe according to my requirement.

 

is it possible or not.

 

 

Thank you

Aruna

Best Answer chosen by Admin (Salesforce Developers) 
NzgonNzgon

It is 2 hours

 

1 day =24 hours

1 hour= 1/24 = 0.0416

2 Hours= 2 * 0.0416 = 0.083

 

Nash

All Answers

NzgonNzgon

Use this to create formula field value and filter by it in list.

 



How can I create an age or duration field in a days, hours, or minute format?
Knowledge Article Number: 96127


Description

How can I create an age or duration field in a days, hours, or minute format?




Resolution

This solution applies whenever you want to express a duration or age, for instance if you want to compare when a record was modified to when it was created, you would compare the "LastModifiedDate" field with the "CreatedDate" field.

To do that, you can create a formula field type of "number", called for instance "D2subD1" that contains this :
{!LastModifiedDate} - {!CreatedDate}

However, the result of this formula is a number whose integer part is the number of days, and whose decimals are hours and minutes expressed as a fraction of 1 day.

For instance, it would return "13.5" for 13 days and 12 hours.

To express this number in the format "13 days 12 hours 0 mn", you need to create another formula field of the type text that contains:

IF ( {!D2subD1__c} > 0,
TEXT(FLOOR( {!D2subD1__c})) & " days " &
TEXT( FLOOR( 24 * ( {!D2subD1__c} - FLOOR({!D2subD1__c}) ))) & " hours" &
TEXT( ROUND(60 * (ROUND( 24 * ( {!D2subD1__c} - FLOOR({!D2subD1__c}) ),8) - FLOOR(
ROUND( 24 * ( {!D2subD1__c} - FLOOR({!D2subD1__c}) ),8)) ),0)) & " mn "
, "")

This can be applied for any subtraction of 2 date/time fields.

ArunaAruna

Hi,

 

I have creted the 2 formula filed , but I am wondering  how to use this filed's in creating view.

 

 

when I am trying to create a view i selected the second formula  there what is the condition i need to create.

 

please suggest me on this.

 

Thank you

aruna

ArunaAruna

Hi,

 

This solution is not working , I need to pull the records which are created  in past 2 hours.

 

I think I need to go for the Vf and Apex.

 

can any one tell me how to write a query to get the records which are created in past 2 hours.

 

Thank you

Aruna

NzgonNzgon

Create custom text formula field with this code:

 

if((NOW()-CreatedDate)<=0.083,'Yes','No')

 

Create list view with filter 

 

Custom Field Name equals Yes

 

You will see just records created last two houre.

 

Nash

ArunaAruna

Hi Nash,

 

what is <=0.083.

 

Thank you very much for the replay .

 

Thank you

Aruna

NzgonNzgon

It is 2 hours

 

1 day =24 hours

1 hour= 1/24 = 0.0416

2 Hours= 2 * 0.0416 = 0.083

 

Nash

This was selected as the best answer
ArunaAruna

Hi Nash,

 

Thank you very much, you solved my problem.

 

 

Aruna

BPOBPO

Can someone help me add seconds to this formula as well as days, hours, and minutes

 

Thanks

 

Bret

NzgonNzgon

1 day =24 hours

1 hour= 1/24 = 0.0416

1 minute=1/(24*60)=1/1440

1 second = 1/(24*60*60)=1/86400