HELLO Salesforce Thinkers, In our previous blog we learned about Formula Fields in Salesforce In this blog we are going to learn about “Date and Time Formula Functions in Salesforce”.

We can include formula functions in formula fields, validation rules, approval processes, and workflow rules.
Date and Time Functions :-
We have the following Date and Time Functions in Salesforce.
1. ADDMONTHS :
Returns the date that is the indicated number of months before or after a specified date.
If the resulting month has fewer days than the start month, then the function returns the last day of the resulting month. Otherwise, the result has the same day component as the specified date.
Syntax: ADDMONTHS(date,num)
Example:
Calculate the First installment submission date of the Student (custom object) which is 4 months after the Admission Date.
ADDMONTHS (Admission_Date__c, 4)
Adds 4 months to the Admission Date. For example, if the Admission Date is July 1, 2020, the resulting date is November 1, 2020.
2. DATE :
Returns a date value from year, month, and day. Salesforce displays an error on the detail page if the value of the DATE function in a formula field is an invalid date, such as February 29 in a non-leap year.
We could use the DATE() function to convert a day, month, and year into the desired Date value.
Syntax: DATE(year,month,day)
Example: If we want a custom formula field to display the date March 17, 2020.
DATE(2020, 03, 17) creates a date field of March 17, 2020.
3. DATEVALUE :
Returns a date value for a date/time or text expression.
In DATEVALUE(expression) replace expression with a date/time or text value, merge field, or expression.
Syntax: DATEVALUE(expression)
Example : DATEVALUE(“2020-03-17”) creates a date field of March 17, 2020.
4. DATETIMEVALUE :
Returns a year, month, day and GMT time value.
In DATETIMEVALUE(expression) replace expression with a date/time or text value, merge field, or expression.
Syntax: DATETIMEVALUE(expression)
5. DAY :
Returns a day of the month in the form of a number between 1 and 31.
Syntax: DAY(date)
6. HOUR :
Returns the local time hour value without the date in the form of a number from 1 through 12.
Syntax: HOUR(expression)
7. MILLISECOND :
Returns a milliseconds value in the form of a number from 0 through 999.
Syntax: MILLISECOND(expression)
8. MINUTE :
Returns a minute value in the form of a number from 0 through 60.
Syntax: MINUTE(expression)
9. MONTH :
Returns the month, a number between 1 (January) and 12 (December) in number format of a given date.
Syntax: MONTH(date)
10. NOW :
Returns a date/time representing the current moment.
Syntax: NOW()
11. SECOND :
Returns a seconds value in the form of a number from 0 through 60.
Syntax: SECOND(expression)
12. TIMENOW :
Returns a time representing the current moment.
We can use this function instead of the NOW function if we only want to track time, without a date.
Syntax: TIMENOW()
13. TIMEVALUE :
Returns the local time value without the date, such as business hours.
Syntax: TIMEVALUE(expression)
14. TODAY :
Returns the current date.
Syntax: TODAY()
15 .WEEKDAY :
Returns the day of the week for the given date, using 1 for Sunday, 2 for Monday, through 7 for Saturday.
Syntax: WEEKDAY(date)
Example: Calculate the day of the week for the Contract Start Date.
WEEKDAY(StartDate)
16. YEAR :
Returns the four-digit year in number format of a given date.
Syntax: YEAR(date)
Example : Calculate the number of years since the start date of a Contract.
YEAR(TODAY())- YEAR(StartDate)
This returns the number of years since the start date of a Contract.
Thanks for reading…