Salesforce Date Format Methods

Salesforce date formats are usually very vital when it comes to managing contract ages, payment deadlines and other time and date-related features of a business establishment. Every date format method is unique and is used in various operations. In the Salesforce system, there are usually two data types that are commonly used when working with dates. They are:
  • Date
  • Date/Time
Most of the values usually used when one is working using the dates are normally of the Date data type that usually store the month, year and day. Some of the fields like CreatedDate are Date/Time fields which simply means that they store both the date and time value which is usually stored in GMT but then displayed in the Salesforce user’s time zone. Both the Date and Date/Time fields are normally formatted in the Salesforce user’s locale when viewed in the reports and the record detail sections.

Salesforce Date Format Methods


Calculating Data Type Values

It is possible to use operations such as subtraction and addition when using the Date and Date/Time values when calculating the future date or any time passed between two dates. When carrying subtraction of one date from another, usually the resulting value will be the difference between the two values calculated. When the same is done between two Date/Time values the decimal value that results usually indicates the number of hours, minutes and days.

A good example, if the difference between two values that are of the Date/Time data type is 5.52, this actually indicates that the two initial values have a difference of five days and 12 hours which is equivalent to 0.5 of a full day and 28 minutes which is equivalent to 0.02 of a full day. It is also possible to add any numeric values to most Dates and Date/Times.

Remember complex date functions are known to compile into a larger size compared to text or number formula functions. It is possible to encounter issues when it comes to the formula compile size but you can always consult the steps involved when reducing formula size that can be found in the Salesforce site under Salesforce date format.

Today & Now Functions

The TODAY function is known to return the day, month and year that is current as the Date data type. This function is very useful when it comes to finding out the number of days that have passed since a certain specific date or the specific date of a number of days in the future. Also when you simply want display only the current date , it is still possible.

The NOW function on the other hand is known to indicate the Date/Time value that is currently available. It is very useful when one wants to know the specific date as well as the time of day. You can further learn about converting Date values and the Date/Time values through the section that explains that clearly in the salesforce website.

The Date Function

The DATE function will give you the year, month and day as the Date Value. The related functions which are YEAR, MONTH and DAY are usually valid parameters for the DATE function. When the Y/M/D values are inputted they usually result in an error which comes with the DATE function. Error checking is therefore an essential part of working with Salesforce date format. You can learn how to handle invalid dates in the Common Date Formulas Section.

Converting Between Date and Date/Time

Date and Date/Time are simply not interchangeable data types. In the event that you need to make two values the same you will have to perform vital operations between the Date and the Date/Time values. Functions such as DAY, MONTH and YEAR have also been known to work on the Date values so one has to first convert the Date/Time values.

You can always use the Date Value function to get the Date Value of the Date/Time. It is also possible to convert a Date value into a Date/Time by use of the Date Time Value function. The time will be set in GMT then later converted to the user’s specific time zone which will be displayed on the records.

Converting Date and Text

When you need to include the date as a part of a certain string, simply wrap the Date value in the TEXT function in order to convert it into a text. For example when you want to convert the current date into text , the return date will come in the text format of YYYY-MM-DD and not the other format. However, you can also change the format by simply extracting the day or month and year from the date then recombining them into the format that best suits you.

Converting Date/Time & Text

It is possible to include the Date/Time values in a single string using the TEXT function, however you will need to be very cautious of the time zones. When a formula NOW() for example is offset to the GMT. Usually the NOW() formula will then be converted to the time zone of the user. However, when it is converted into text, the conversion normally doesn’t happen. Therefore when executing such a formula it is advisable to result is usually a current date with a Z at the end which means blank. So instead of converting to text check for that first and set the value for the blank part. Use the DateTime Value to convert the string to a Date/Time value.

Note The Date/Time & Time Zones

Remember that the Date and the Date/Time values are usually stored in the GMT. The field values are then adjusted to the user’s time zone when displayed in the record detail section and reports. With the Date conversions this isn’t usually an issue because converting a Date/Time to a Date often times results into a similar Date value.

However, when you are working with the Date/Time fields and the values, the conversion is normally done in GMT and not in the time zone of the user. Subtracting the standard Date/Time field from another is never an issue because the two fields are in a similar time zone. The results then get different only when one of the values in that calculation is a conversion from the Text or the Date Value to the Date/Time value. For additional how to add fields in salesforce and get all the benefits.

With the above guideline it is possible to successfully use the Salesforce date format method to meet the needs of your business.
mm
Amanda is the Lead Author & Editor of Rainforce Blog. Amanda established the Rainforce blog to create a source for news and discussion about some of the issues, challenges, news, and ideas relating to Salesforce usage.