Salesforce Date Functions – A Short Guide

Date functions are a useful feature of Apex programming in Salesforce. They provides a lot of useful functionality inside forms, plugins and in record-sets themselves. Time stamps and time comparisons are vital in CRM records – especially when it comes to accuracy and record keeping for legal issues.

The methods provided in Apex are not complicated, but you may not be familiar with them, So, today I’m going to go over a few of the many Salesforce date functions and outline what each is used for.

(Due to privacy concerns, I cannot give you code samples, so I will refer you to Salesforce’s Apex programming examples for anything more in-depth than a description).

#1 – DaysInMonth

You’d be surprised how often the simple things can cause a big mess. How many of you know how many days are in each month? What about working days? This is basic, yet critical information for forecasting cost, totaling fiscal information and incorporating logistics. DaysInMonth makes determining this rather easy. All you have to do is provide two sets of integers – a month and 4-digit year- and you will get number of days in that month as an integer.

#2 – Today

Today is a constant ‘date value’ that can be input into form values or calculations. The feature will return an image (date type object) reflecting the month, date, day of the week and year which apply.

#3 – DaysBetween

DaysBetween allows you to compare dates. This feature is very valuable, because calculating time spans between dates is something that CRM forms have to do- constantly. (Most other systems require raw code to handle this). Apex has a built in method of the date type object to do it for you, which saves time and code.

#4 –isStartOfWeek and isStartOfMonth

These are similar tools. They start off with a date and return a Boolean value of true or false. These tools are very useful, because the start of a fiscal period has to be factored in CRM and financial software forms.

There are many Salesforce date functions available, and their features are constantly being updated. Check out the list above and let me know what you think.

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.