Use these tips to avoid unexpected results in Date and Date/Time calculations. Learn
about data type compatibility, calculating durations and intervals, handling fractional day
values, and staying within valid year ranges.
Required Editions
Available in: both Salesforce Classic and Lightning Experience
Available in: Essentials, Group, Professional,
Enterprise, Performance, Unlimited, and Developer
Editions
Dates and Times are always calculated by using the user’s time zone.
Don’t use Date and Date/Time fields interchangeably. The name alone doesn’t always
indicate when a field is a Date or Date/Time. For example, Created Date and Last Modified
Date are Date/Time fields whereas Last Activity Date is a Date field. Use the DATEVALUE
function to convert a Date/Time field into a Date field.
Note The Created Date and Last
Modified Date fields show only the date, not the date and and the time.
Use addition and subtraction operators with Date or Date/Time fields to calculate
duration. For example, subtract a date from another date to calculate the number of days
between the two. Likewise, you can subtract the Date/Time from another Date/Time to get
the number of days between the two as a number. See NOW() or
TODAY() for suggested use.
Use addition and subtraction operators with numbers to return another Date or Date/Time.
For example, {!CreatedDate} + 5 calculates the date and time 5 days after
a record’s creation date. The expression returns the same data type as the one given. A
Date field plus or minus a number returns a date, and a Date/Time field plus or minus a
number returns a Date/Time.
When calculating dates that use fractions, Salesforce ignores any numbers beyond the
decimal. For example:
TODAY() + 0.7 is the same as TODAY() +
0, which is today’s date.
TODAY() + 1.7 is the same as
TODAY() + 1, which is tomorrow’s date.
TODAY() +
(-1.8) is the same as TODAY() + (-1), which is yesterday’s
date.
To calculate the value of two fractions first, group them within parentheses. For
example:
TODAY() + 0.5 + 0.5 is the same as TODAY() + 0 + 0, which is today’s date.
TODAY() + (0.5+0.5) is the same as TODAY() + 1, which is tomorrow’s date.
Years can’t be zero and requires a value between -4713 and 9999.
We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required Cookies
Always Active
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional Cookies
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising Cookies
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.