+ Start a Discussion
SandrineSandrine 

calculate time in minutes between last modified date

Hello,

How can i calculate time between last modified date and present modified date and get the time in minutes.
where can i store t, in number field or text field.

thank for suggestion
Best Answer chosen by Sandrine
Ajay K DubediAjay K Dubedi
Hi Sandrine,

Try the following code:

Date d1 = Date.newInstance(1990, 1, 1);
Date d2 = Date.newInstance(2008, 1, 30);
Integer numberofDays = d1.daysBetween(d2);
Integer timeinminutes= (numberofDays)*24*60;
System.debug('difference between two dates'+timeinminutes);

This will result output in minutes.
As per your query you must follow:

Integer timeinmin=(lastmodifieddate - presentmodifieddate)*24*60;

Store the diffrence using Number data type.
Mark it as best answer if this explanation was helpful.

Thanks.
Ajay Dubedi

All Answers

Sandeep YadavSandeep Yadav
Hi Sandrine
You can store minutes in Number field type.
Present Modified date means you are updating the record today so you can get the current time  by using this --- system.now()
Time_Difference__c = (LastModifiedDate - system.now()) * 24 * 60 

Mark this answer as solved if its help you.
Raj VakatiRaj Vakati
Try this
 
(NOW() - LastModifiedDate) * 24 * 60

 
Ajay K DubediAjay K Dubedi
Hi Sandrine,

Try the following code:

Date d1 = Date.newInstance(1990, 1, 1);
Date d2 = Date.newInstance(2008, 1, 30);
Integer numberofDays = d1.daysBetween(d2);
Integer timeinminutes= (numberofDays)*24*60;
System.debug('difference between two dates'+timeinminutes);

This will result output in minutes.
As per your query you must follow:

Integer timeinmin=(lastmodifieddate - presentmodifieddate)*24*60;

Store the diffrence using Number data type.
Mark it as best answer if this explanation was helpful.

Thanks.
Ajay Dubedi
This was selected as the best answer
Adam Cadman 4Adam Cadman 4
@Ajay
As you use an Integer to for the 'daysBetween' this will only ever return the number of minutes between the two dates, to the nearest day - it won't give you the actual number of minutes (to the nearest minute)