DATEDIFF
Calculates the difference between two dates, returns the amount of time in the specified units (day, year, month etc.) between a start and end date.
Syntax
int? DATEDIFF(string part, DateTime? startdate, DateTime? enddate)
Input
Object | Data Type | Description |
---|---|---|
part | String | A string to represent the time unit (year,month,day,hour,minute,second). |
startdate | DateTime | A start DateTime. |
enddate | DateTime | An end DateTime value. |
Example
You can use the function to calculate the number of months between two dates, for example:
DATEDIFF("month", DATEVALUE("2016-05-02"), DATEVALUE("2017-02-25"))
Will return '9' as there are nine months between the two dates.
Alternatively you can calculate the number of days between a created date and today by using:
DATEDIFF("day", TODAY(), CreatedDate)
This will return the difference in days between Today's date and the date stored in the CreatedDate field for each record.