Advanced Date Template Logic

SMS Reminder Template Logic

GReminders is a great way to automate SMS, Email or Phone reminder or follow up notifications to your Clients. The system also has a very advanced Content Template mechanism built on the Liquid Templating Library. (Thank you Shopify, they were the creators of the initial library, we all build on the shoulders of Giants)

Recently we had a customer ask if they could send a Reschedule Link to their customers but ONLY if the appointment was more than 6 months into the future. (this was a good opportunity to show everyone the power of the template system)

Content Templates support light coding, and thus also support concepts such as variables and basic if then logic.

So first we need to convert date/times into “numbers” so we can do some basic greater than/less than operations.

In the date/time world there is such a thing called UNIX Epoch Time which transforms a point in time into a number, the number is the number of seconds from the date Jan 1, 1970. If you haven’t heard of that its ok, its a bit strange but computers prefer numbers to dates/times and it works and is commonly used in coding.

So what we want to do here is create 2 variables. The first is converting the existing start date/time of the event into a number like so:

{% assign event_start_date = event.date_time_advanced | date: '%s' %}

What this does specifically is sets the variable “event_start_date” to a number using our GReminders variable of “event.date_time_advanced” and putting it through the date function where %s converts it to a number.

Next, we want to create another variable that is 6 months away from today like so:

{% assign future_date = 'now' | date: '%s' | plus: 15768000 %}

This sets the variable of “future_date” equal to “now” (which is literally right now) converts it to a number (using the date function like above) and then ADDING “plus” 6 months worth of seconds (so 60 seconds * 60 minutes * 24 hours * 182 days) = 1576800 (1576800 seconds = 6 months)

Now we have 2 numbers in 2 variables. From here it is very easy to compute.

If we simply wanted to output the numbers we could do this:

Start Date: {{event_start_date}}
Future Date: {{future_date}}

But we want to do something a bit more useful so we can do something like this:

{% if event_start_date > future_date %}
Allow client to Reschedule
{% else %}
Dont allow client to reschedule
{% endif %}

Putting it all together:

{% assign future_date = 'now' | date: '%s' | plus: 15768000 %}
{% assign event_start_date = event.date_time_advanced | date: '%s' %}
Reminder, you have an appointment with {{user.firstname}} {{user.lastname}} at {{event.time}} on {{event.date}}.
{% if event_start_date > future_date %}To Reschedule please go here: {{event.reschedulelink}}{% endif %}

Outputs:

Reminder, you have an appointment with Michael Scott at 3:30pm on Tuesday Dec 20.
To Reschedule please go here: https://greminders.com/r/xxxxxx

Since Dec 20 is more than 6 months away (we are writing this on May 10), the output will show the reschedule link. If not it wont show the last sentence.

Yes, we know code can be a bit intimidating, but give it a try if you have some more advanced scenarios you want to try out.

Can’t figure it out? No problem, just reach out to [email protected] and we will help you.

Happy Scheduling.

Want to Eliminate No Shows? Try GReminders today for Free

Try It Free Today!