1

I have a datetime field field1 which i am populating using NOW() formula. At some point later i want to know the difference between NOW() and field1 in number of days.

I tried NOW()-field1 and DATETIMEVALUE(NOW()) - DATETIMEVALUE(field1), but it does not seem to be correct.

I am storing this result in a number field which can store 6 decimal places. But when i multiply the value by 60*24, it does not return correct result. If the difference is 12 hours between NOW and field1, I want the field to have .5 as value. If the difference is 6 hours, it should have .25

1
  • NOW() - DateTime_Field__c works very well for me. Why do you mean it isn't? Mar 14, 2016 at 14:19

3 Answers 3

2

I think your approach is right, but you should use only 2 decimal places in your formula number field.

I have tested the following:

  • NOW() field (DateTime formula)
  • DateTime field
  • Difference field with formula NOW()- ut__Datetime__c (number formula, 2 decimal places)

Works well:

enter image description here

2

You can use this.

Now()-Field1__c - FLOOR(Now()-Field1__c)

For more info go to the Link

2

If you use it in Apex, this works:

(f2.getTime() - f1.getTime()) / 1000 / 60 / 60 / 24;

first you calculate difference in milliseconds between datetimes, then get number of days from it.

You must log in to answer this question.

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