๐ŸŽ“ [Getting Started With Functions p. 3] Date Functions

Hey Makers :wave:

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.

:student: 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.

:wave: Introduction to timestamps :wave:

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? :partying_face: :neutral_face::confused:



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.

:spiral_calendar: Manipulating dates :spiral_calendar:

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.




:white_check_mark: What we have so far :white_check_mark:

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!


:muscle: 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.




Please let us know in the comments below if you have any questions and what else you would like to see as part of this functions series!

2 Likes

Amazing post. Thank you!

2 Likes

Heya @kaan welcome to the community :wave:

Iโ€™m stoked to hear that you find the post helpful!

Btw if you have any ideas/suggestions on what we should cover in our future posts, feel free to let us know in this thread :slight_smile:

Thanks for the post! Iโ€™m running into an issue where one of my apps sends over UTC date and then the app that received the date has Eastern zone, so the resulting date in the final location is a day earlier than intended. For example, I have the Start Date as March 27 in my CRM, but then the Invoice in my other app receives and spits out the Start Date as March 26.

My initial solution was to add a day in the Make step so that the invoice would correctly read March 27 BUT I also am using a function to calculate the end date: addMonths ([start date]; [committed months]).

So, whatโ€™s the best way of handling timezones and UTC? And am I able to have a date function that adds a month AND a day to the original start date?