+ Start a Discussion
Baktash H.Baktash H. 

Get Date difference?

Hello I have a simple Problem,

I have the CreatedDate field of an Object, and instead of the date i need the difference between now and the Date,

because I want to show it in the Visual Force like this for example:

5 Hours Ago or

10 day Ago.

 

I didn't find a method to calculate such things.

 

Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
Baktash H.Baktash H.

Thank you, I think thats the right way but i still don't get it worked...

I create the Formular field, and I tried:

Age = Now() -  CreatedDate

and the return type number...because its a difference. But i don't know what i get? Does it give me the difference in seconds, hours, days or even years?

 

I displayed it on the VF page and the result for the records are all 0, which confuses me more...do you know how i can solve this?

//////Edit:

Okay i tried sth. new: I turned the Decimal placed to 18, before that it was 0.

Now i get numbers like this:

0,016898148148148148 <- a record which is 24 minutes old.

0,010821759259259259 <- a record which is 18 minutes old...

 

now the question is, how do i calculate that to minutes? I don't even know what that little number is....maybe 1 is one day and 0.01 is 1% of a day, which is 14,4 minutes? That would make sence, wouldn't it?

 

I solved it.

Age = (Now() -  CreatedDate) * 1440

the result is in minutes.

 

Thanks.

All Answers

VarunSforceVarunSforce

This somthing like calculating age for the record. You can build a fomula field. Using two dates ( createdate and now)  and display on VF page.

Baktash H.Baktash H.

Thank you, I think thats the right way but i still don't get it worked...

I create the Formular field, and I tried:

Age = Now() -  CreatedDate

and the return type number...because its a difference. But i don't know what i get? Does it give me the difference in seconds, hours, days or even years?

 

I displayed it on the VF page and the result for the records are all 0, which confuses me more...do you know how i can solve this?

//////Edit:

Okay i tried sth. new: I turned the Decimal placed to 18, before that it was 0.

Now i get numbers like this:

0,016898148148148148 <- a record which is 24 minutes old.

0,010821759259259259 <- a record which is 18 minutes old...

 

now the question is, how do i calculate that to minutes? I don't even know what that little number is....maybe 1 is one day and 0.01 is 1% of a day, which is 14,4 minutes? That would make sence, wouldn't it?

 

I solved it.

Age = (Now() -  CreatedDate) * 1440

the result is in minutes.

 

Thanks.

This was selected as the best answer