+ Start a Discussion
Shruti VishShruti Vish 

Difference between 2 datetime fields

I want to get difference of num of days between createddate and current date weather i should use now or today function

TODAY() and NOW()
The TODAY() function returns the current day, month, and year as a Date data type. This function is useful for formulas where you are concerned with how many days have passed since a previous date, the date of a certain number of days in the future, or if you just want to display the current date.
The NOW() function returns the Date/Time value of the current moment. It’s useful when you are concerned with specific times of day as well as the date.
For details on how to convert between Date values and Date/Time values, see Converting Between Date/Time and Date.
Hi Shradha,
you need to convert created date into date format and then use daysbetween()
for eg:-
Account acc = [ SELECT CreatedDate From Account Limit 1];
Date myDate = date.newinstance(acc.CreatedDate.year(), acc.CreatedDate.month(), acc.CreatedDate.day());
system.debug( myDate.daysbetween(Date.Today()));