Simple date subtraction, as Amit suggests in the comments, would be a decent approximation. Datetimes (and their closely related cousin, Dates) can be subtracted to give you a decimal (in the case of Datetime) or integer (in the case of Date) result telling you how many days difference there is.
It doesn't matter if they're in the same month or the same year. Salesforce handles that detail for us so we don't need to worry about it. I suspect Salesforce stores both as a timestamp, and then does some relatively simple math to arrive at a result.
A simple
AND(
NOT(ISBLANK(End_Date__c)),
TODAY() - End_Date__c < 90
)
would suffice in most cases (the result of a comparison such as "less than" results in a Boolean, no need to wrap it in an IF()
), but would fall short if you need 3 "full months" (for whatever definition of "full month" you use if End_Date__c is somewhere in the middle of the month).
If End_Date__c is in the future, then you'd either swap the order of the arguments to subtract, or simply use ABS()
to turn any negative values into positive ones.
Another option, as Kasper suggested, is to use the ADDMONTHS()
function, which ought to handle year boundries for you.
AND(
NOT(ISBLANK(End_Date__c)),
ADDMONTHS(End_Date__c, 3) < TODAY()
)
Best Answer
TimeNow()
returns the current time in GMT. When the user views a Time field it's converted to their local timezone, but the value in the field is also always stored as GMT. The almost-84 million number you're getting is the result of subtracting a later timevalue from an earlier one - rather than give a negative number, the system appears to calculate it as if the second number was actually that time the previous day. There are 84,400,000 milliseconds in a day, so your number would indicate the actual value fromTimeNow()
is just after midnight. You said you were trying at 3:34 PM Local time, so I'm guessing your offset is set to UTC -9:30 (French Polynesia) which would give a GMT time of 00:04, just before your subtracted value of 00:17.Since you said you wanted to test since 5 PM local time, you'll need to account for your time offset, so your formula should be the following to get the time in milliseconds: