← Alle Artikel

Calculate Duration between two Dates in Make (formerly Integromat) 2021

Veröffentlicht: March 2, 2022·
Calculate Duration between two Dates in Make (formerly Integromat) 2021
Calculate Duration between two Dates in Make (formerly Integromat) 2021
1hWG3jcTpk0

When working with Make (formerly Integromat), you most likely also work with dates, or you have to work with dates and dates can be really confusing. In this blog, you will learn how you can calculate the difference between two dates to know the days in between or even the days, the hours, the minutes and the seconds. 

We look at it using an example, and I will explain to you all the functions that you will need and how to set it up. 

The Sample Scenario: Two Dates in Make

I've prepared this sample scenario. 

The sample scenario with two variable modules holding Date 1 and Date 2

We have Date 1, which is the 8th of September, and we have Date 2, which is the 9th of April. 

The two date values entered as variables

We want to see the difference between these two dates. You could theoretically do ‘Date 1  minus Date 2’. But when you run this once, you see the time difference, it's just empty.

The subtraction of the two raw text dates returns an empty result

Why is that? Because it understands this as a text string. And for a text string, you can't make a calculation. You can't say day one minus day two. We have to parse the date first. So we use the parseDate function. 

Step 1: Convert Text to Real Dates with parseDate

The parseDate function basically transforms the string into an actual date, and then you can do more things with it.

The parseDate function in the Make function picker

Add the parseDate function in the variable value on both dates.

Both date variables wrapped in the parseDate function

If we run it once again, we see it still looks exactly the same. But the output of this function is now actually, time, that is, in milliseconds. That's basically the time difference between these two dates in milliseconds.

The run now returns the difference in milliseconds

Step 2: Get the Difference in Seconds with formatDate

But how do we show the time difference between these two dates in seconds? 

Let’s format them into seconds. We can do this using the formatDate function. 

As the value for the format, we use the uppercase X, which means seconds. You could also use the lowercase x, which is milliseconds, and that will give the same output as if you calculated the difference right away.

The formatDate function with the uppercase X format for seconds

Run it once and below are the results in milliseconds and seconds.

The result of the difference in milliseconds
The result of the difference in seconds

With seconds, you can easily calculate everything. You could also do it in milliseconds. You just have to divide it by 1000, and then you get the actual seconds. 

Step 3: Calculate the Days with the round Function

The next step would be to calculate the days. How many days are there between two dates? 

There's this handy function called the round function. 

The round function combined with the divisions for days

We have date one minus date two. Then we divide it by 1000. Divide it by 60, divide it by 60 again, and lastly, divide it by 24. Why is that? Because we have 24 hours a day, 60 minutes an hour, 60 seconds a minute, and 1000 milliseconds a second.  

Since the output is in milliseconds, we have to divide by 1000 to get the value in seconds.  Then we divide it by 60 to get the value in minutes. Then we divide it by 60 again to get the value in  hours, and then we divide it by 24 to get the actual number of days. 

So the output is 152, as you can see here. 

The run returns 152 days between the two dates

Check the results over on Google and see. 

A Google date calculator confirming the 152 days

Step 4: Split the Difference into Hours, Minutes and Seconds

Now we want to get hours, minutes and seconds split up.

Divide the date difference first by 3600 to get the hours, and we use the floor function to round it down to the full hour, because we don't want, like, 3600.57 hours because that doesn't make sense. So we divide by 3600. 

For the minutes, we have the floor function as well. We use the value that we had before this same variable.  Then we use modulus 3600, which means it is divided by 3600 and then give back the rest. Divide that value by 60.  That gives us the minutes. 

Do the same for seconds. Use modulus 3600, which gives the rest of the first function of the hours. Then again, modulus 60, which gives the rest of the minutes. And that is the second. 

The floor and modulus formulas for hours, minutes and seconds

So now running that again, it is 3656 hours, 47 minutes and 45 seconds. 

The result split into hours, minutes and seconds

Step 5: The Full Breakdown with Days, Hours, Minutes and Seconds

Now, let’s make this a bit more complicated, shall we? Let’s add in the days.

The main difference is we divide it by 86,400, because 86,400 is how many seconds one day has. 

Divide the time difference in seconds by 86,400, then use the floor function to round it down to the full number to get the number of days. 

Use the modulus function again to get the rest of it and divide it by 3600 like we did before to get the hours. 

Use the modulus two times again, with 86,400 to get the days, then 3600 to get the hours and then divided by 60 to have it in minutes.

Last but not the least, do the same with modulus 86,400, modulus 3,600 and modulus 60 to get the seconds.

The complete formulas for days, hours, minutes and seconds

The output is 152 days, 8 hours, 47 minutes and 45 seconds.  That's exactly what the time difference is between these two dates. 

The final output: 152 days, 8 hours, 47 minutes and 45 seconds

You can use this however you want to, and however you need it. If you want to say okay, time difference needs to be exactly 30 days and 50 seconds, then you can set up a filter that the days and the seconds should be above that value or the total seconds should be above that value.  You can also save the result into a custom field and use it further. 

I hope the explanation was helpful for you because I know times are quite hard to grasp. I will provide more blogs about times, working with times and timestamps and working with different time zones in the future. 

If the functions I used here look useful but you are not sure how they work, Make's own function reference explains every available function with its parameters — it is the fastest way to look up exactly what a function does while you build your scenario. 

Key Takeaway

Make functions are super helpful.  They provide a lot of value, as I have just recently demonstrated, and they enhance your automation without using any additional action. Every action costs a credit, and you save a lot of credits by solving things with functions instead of extra modules. The thing about using Make is that you can have a high degree of control over your processes and have them perform without any intervention from you. Consider the many areas where integrating your business processes can lead to significant benefits. You can use Make when handling & automating tasks for operations management, human resources and delivery services, to name a few. 

Learn more about what else you can automate in Make by taking the Make Simplified Accelerator. It's an interactive course where you will be able to learn the basics of Make and get to know its most used features. There will be several lessons for you to learn, along with some quizzes to help you understand the information. It's an affordable way to learn what you have always wanted to know about Make!

MGManuel Gick, Gründer von Techflow.ai
Manuel Gick

Founder of Techflow.ai. Certified Make.com trainer, university AI certificate (Hochschule Fresenius). Writes about AI agents, automation, and custom software for SMEs.

Transparenz: Beiträge auf dieser Seite können Empfehlungs-Links zu Make.com und Langdock enthalten. Nutzt du sie, erhalten wir eine Provision — für dich ändert sich am Preis nichts.

Zeit-Potenzial-Analyse

Rechne nach. Gewinn zurück.

45 Minuten, kostenlos, kein Verkaufsgespräch. Du gehst raus mit deinen Top-3 Zeitfressern und einem konkreten Plan für den ersten Sprint.

Zeit-Potenzial-Analyse buchen →