Hey Makers
Just stepping in with the third part of our Getting Started with Functions series.
This time around, weโre taking a look at Date functions and how to use them on Make.Check out the previous episodes of the series:
๐ [Getting Started with Functions p. 1] General Functions
๐ [Getting Started with Functions p. 2] Math Functions
The previous parts of this series introduced general and mathematical functions and showcased how they can be used in real-life automations to transform and manipulate data to achieve useful outcomes.
This article will explore Date functions and provide you with some examples on how they can be applied to the quote generation solution you have seen earlier.
Did you ever need to store the time that your scenario has been executed or schedule a meeting for three days in the future? Being able to retrieve the current date and time is a core part of these types of use cases.
In Make, the current date/time can be retrieved using the now
variable.
However, the format of this date/time value might not be as readable as you would expect it to be.
This format is called ISO 8601 and itโs the international standard for the communication of data related to date and time.
It can get worse, though. Try choosing the timestamp
variable instead.
This will populate a long, ugly number which doesnโt mean much, at a first sight.
What if I told you that this is the number of seconds that elapsed since midnight of January 1, 1970*.
Exciting, right?
Maybe notโฆ
but these date/time formats are actually quite important because this is how computers understand time.
Telling Google Calendar to schedule a meeting for you at 05/06/2023 is quite straight forward because you can choose the date and time on a nice user interface designed to make the life of the end-user as easy as possible.
Behind the scenes though, the server (a.k.a computer) that will process and store this information, will have to convert the input date to a timestamp in a standardized format (e.g. Unix timestamp).
Similarly, when interacting with different Make apps, there are cases where you can enter a date in the readable MM/DD/YYYY format:
and others where the date/time format needs to be a timestamp:
It all depends on the level of abstraction each app module offers.
Working with timestamps, however, can provide you with huge benefits.
In the above scenario, we have a Slack > Create Reminder module. As the name of the module suggests, its aim is to automate the scheduling of reminders.
Letโs say that each time this module gets executed we want to set a reminder for 3 days in the future. To achieve this we would have to retrieve the current date/time, as a timestamp, and then increment its value by 259200 seconds (= 3 days).
This formula wouldnโt work if our current date/time was in MM/DD/YYYY format, simply because a computer cannot add seconds to a date. A date (as we know it) and a timestamp, are seen as two different data types.
Once a date is in timestamp format you can start making use of Make functions to manipulate it.
In the example below, weโre using the addYears function to increment the current date by 2 years.
Since this tutorial is being written in 2022, the result date has the same day, month, and time, but the year is 2024.
The addSeconds, addMinutes, addHours, addDays and addMonths functions all follow the exact same principle. As long as you provide them with a date in timestamp format, they will transform your date accordingly.
In the previous part of this series, we showed you how to generate a quote with dynamic tags which can be populated with data using the Google Docs > Create a Document from a Template module. However, the previous version of the quote did not include a Quote Date or a Valid Until Date.
The values of these dates can be dynamically populated using Date functions.
The Quote Date field should contain the date that the quote was generated on. For more use cases, this will usually be the current date, which can be retrieved using the now
variable.
However, the goal is to display the current date in a readable format, therefore we used the formatDate function to make sure the date is converted to MM/DD/YYYY.
For the Valid Until Date we want to set the value of this field to a date that is 15 days ahead of the current date.
This can be easily achieved using the addDays function, seen above. However, it is important to still wrap the addDays function in the formatDate function to make sure the result date is in the readable MM/DD/YYYY format.
And just like that, dates are now being populated on your quotes automatically and you also have all the knowledge you need to start applying Date functions to your scenarios!
Putting together all the processes we went through in this series, you should now be able to automate the generation of accurate sales quotes for project requests submitted by your prospects.