Loading
Prepare for Email to Become the Default Login ExperienceRead More
Extend Salesforce with Clicks, Not Code
Tips for Working with Date and Date/Time Formulas

Tips for Working with Date and Date/Time Formulas

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
    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.
 
Loading
Salesforce Help | Article