# Using Dates in Computation Rules

### General

When dealing with loans, a lot of things are measured in time. This can be anything from the number of days since a payment was last made to how long until a loan is paid off. As a result, working with time, particularly with dates, is a very important part of the computation rules in LoanPro. Working with dates is different than working with numbers, so this article will go over the basics of using dates in the computation rules.

When you want to compute a specific date, make sure your output format is set to “Date”. When you want to get how much time is between two dates, make sure your output format is set to “Number”.

#### Getting Today’s Date

Most often we want to compare things with today’s date. We want to know how far into the future or how long ago something is or was. As a result, we need to know the current day. To do that, LoanPro has two options for getting the date. The first is the following special command:

(u/today :format :date)

The above function, u/today, will get the current date from the system at the time the rule is evaluated. This date will be in UTC time, and is pulled from the LoanPro servers. Go ahead and make a computation rule with just the above as your formula and see what it evaluates to. Remember to set your Output format to “Date”.

The other option, which is the most common, is to use the current-date variable. This will get the current date, based on the tenant timezone. This variable will output a date string.

#### Using Date Variables

There are several variables that use dates. Each variable that contains a date will have a format like the following:

Date *(YYYY-MM-DD)*

This means that the variable will return a date with the year first, followed by the month, and then by the day of the month. For example, August 1st, 2015 would be evaluated to 2015-08-01.

For this article, we’re going to use the Next Due Date variable. Create a new computation rule and find the Next Due Date variable, but don’t put it into the formula text box quite yet.

#### Comparing Dates

Often times we want to compare two dates to see what the difference is. However, using the minus “-” operator doesn’t work with dates, so LoanPro uses the operator “u/date-compare”.

Unlike other operators, this one only works with two dates, and instead of evaluating to a date it evaluates to the number of days between the two dates. Basically, it subtracts the first date from the second date, so if the second date is larger than the first date you will get a negative number, otherwise you will get a positive number.

So, let’s say I want to know how many days it’s been since the last payment date for a loan. I would enter the following for my formula:

(u/date-compare current-date last-payment-date)

Most often this will return a negative number that represents the number of days in the past that the last payment date occurred. If I want to know how many days until the next due date I would enter the following:

(u/date-compare current-date status-next-payment-date)

This would give me a positive number representing the number of days until the next due date for a loan.

When comparing dates, if I flip the order of the dates, then I flip the sign of the result.

##### Compare Dates with Banking Days

**This is a new feature with LoanPro's latest release.**

The "u/date-compare" operator tells you the number of calendar days between two dates, but sometimes you'd like to know the number of banking days. In these cases, you can use the operator "u/banking-days-between", which, as the name suggests, counts the number of banking days between two dates. It works similar to "u/date-compare". Suppose I wanted to know the number of banking days between its been since the last payment was made. Here's the formula I could use:

(u/banking-days-between current-date last-payment-date)

These non-banking days include weekends (Saturdays and Sundays) and certain federal banking holidays:

- New Year’s Day (January 1st)
- Martin Luther King Jr. Day (3rd Monday of January)
- Presidents Day (3rd Monday of February)
- Memorial Day (Last Monday of May)
- Independence Day (July 4th)
- Labor Day (1st Monday of September)
- Columbus Day (2nd Monday of October)
- Veterans Day (November 11th)
- Thanksgiving Day (4th Thursday of November)
- Christmas Day (December 25th)

#### Adding and Subtracting Days from a Date

Sometimes we want to know the date so many days before or after a different date. For example, maybe we want to know which date is five days past the next due date so we can send a late payment notice if the customer doesn’t pay on time. This is accomplished with two different operators, “u/date-+” to add days to a date and “u/date−−” to subtract days from a date. These operators require the first operand to be a date and the second operand to be a number. The following code examples would work:

(u/date-+ current-date 5)

(u/date-+ current-date (u/date-compare status-next-payment-date loan-create-time))

The following code examples don’t work:

(u/date-+ 5 current-date)

(u/date-+ current-date loan-create-time)

#### Dates Before or After a Specific Day of the Month

LoanPro provides two functions that let you evaluate whether a date is before or after a specific day of the month. These functions are:

- u/before-nth-of-month
- u/after-nth-of-month

#### Days in the Month

Sometimes it may be beneficial to use the number of days in the month in a rule. There is a function that will tell you how many days are in the month of any date you pass to it. The function is:

- u/number-of-days-in-the-month

The syntax for this function is as follows: (u/number-of-days-in-the-month “2017-12-24”). As you can see, we have the function and the date of December 24, 2017 is being passed to it. In this case, there are 31 days in December, so the function will output 31.

If you don’t pass a date to the function, it will return the number of days in the current month. As an example, you may use the function without a date to determine if the next payment is less than a month away. The rule would look something like this:

**(< (u/date-compare status-next-payment-date current-date) **

**(u/number-of-days-in-the-month))**

#### Using non-variable dates

Sometimes we want to compare dates to a specific point of time that won’t change based on loan settings. For example, we may want to know how many days have passed since February 23rd, 1994. To use a static or non-changing date, we must put it in quotation marks and have the year, then the month, and then the day. Once we do this, we can use it like any other date. For example, to use February 23rd, 1994 as a date, we would type

“1994-02-23”