Calculate the years since a milestone
You can build a flow to calculate the years since an important date, such as an anniversary, when one of your customers opened an account, or another important milestone.
In this tutorial, you’ll create a new flow that calculates the years since Postman’s founders founded the company. However, feel free to use your own milestone instead.
Create a new flow
You build flows in a workspace. Workspaces let you organize your API projects and collaborate with your team.
To create a new flow, do the following:
- Choose an existing workspace or create a new one.
- In the upper left corner, click New >
Flow.
Create a variable for the current date and time
When you run a flow, the Now block gives you the current date and time, which you’ll need to calculate the years since the milestone.
Add a Now block
- From the canvas toolbar, select
Block.
- Click
Now. If you want to search for the block, enter Now in search.
- Decide where on the canvas you want to place the Now block and select that location.
Connect a Create Variable block
When you connect two blocks, you connect one block’s input to another block’s output. Inputs are on the block’s left side and outputs are on its right side.
It’s optional to connect a Create Variable block. However, if you plan to use a value in multiple places, the best practice is to create a variable. These steps will also let you separate your logic.
To connect a Create Variable block, do the following:
- Hover over the Now block’s output port. The pointer changes to a crosshair.
- Decide where on the canvas you want to place the Create Variable block and drag the port to that location.
- Click Create Variable. If you want to search for the block, enter Create Variable in search.
- Enter the variable’s name. For example, enter now.
Group your blocks
In this tutorial, you’ll separate the logic to get the current date and time from the logic to calculate the years since the milestone and other logic. You can group blocks to better separate this logic.
To group your blocks, do the following:
- Press and hold the Command or Ctrl key.
- Click the blocks you want to group. The canvas’s flyout menu appears and displays the number of blocks you clicked.
- Hover over the canvas’s flyout menu and click
Group selection.
- Hover over the group’s title and click
Edit title.
- Enter a name. For example, enter Now.
- Press the Return or Enter key.
Create a variable for the milestone
In the following set of procedures, you’ll add a Record block to store the milestone date and other milestone-related information.
You could add a Date block instead. However, the Record block resembles the kind of information an API returns to you. In other words, these steps will prepare you to build more complex flows in the future.

Add a Record block
- Decide where on the canvas you want to place the Record block and right-click that location.
- Click
Record. If you want to search for the block, enter Record in search.
- Click
Add data blocks and select
String. If you want to search for the block, enter String in search.
- Enter the string’s key and value. For example, if the milestone is for a company, enter company and Postman, respectively.
- Click
Add data blocks and select
Date. If you want to search for the block, enter Date in search.
- Enter the date’s key and value. For example, if the milestone is a company’s founded date, enter founded and October 14, 2014, respectively.
Optionally, add more data blocks. For example, to build on the previous steps, you can create a more complex data structure to represent the company’s founders. In this case, you could add a list of records, where each item in the list represents a founder, and each record stores the founder’s details.
Connect a Select block
- Hover over the Record block’s output port. The pointer changes to a crosshair.
- Decide where on the canvas you want to place the Select block and drag the port to that location.
- Select
Select. If you want to search for the block, enter Select in search.
- Click Enter path and select the Record block’s date key. For example, if the milestone is a company’s founded date, choose that date.
Connect a Create Variable block
- Hover over the Select block’s output port. The pointer changes to a crosshair.
- Decide where on the canvas you want to place the Create Variable block and drag the port to that location.
- Select Create Variable. If you want to search for the block, enter Create Variable in search.
- Enter the variable’s name. For example, if the milestone is a company’s founded date, enter date.
Group your blocks
- Press and hold the Command or Ctrl key.
- Click the blocks you want to group and select
Group selection.
- Hover over the group’s title, click
Edit title, and enter a name. For example, enter Postman.
- Press the Return or Enter key.
Create a variable for milliseconds per year
When you finish this tutorial, you’ll calculate the difference between now and the milestone date. However, this calculation will return an answer in milliseconds. For this reason, you must calculate millisecond per year and divide by this value to calculate the difference in years.
In this set of procedures, you’ll calculate the average milliseconds per year, which takes leap year into account. However, note that while this is a great approximation, there are more exact methods to calculate the exact value.
Add an Evaluate block
-
Decide where on the canvas you want to place the Evaluate block and right-click that location.
-
Select
Evaluate.
-
Add the following to the code editor:
Connect a Create Variable block
- Hover over the Evaluate block’s output port. The pointer changes to a crosshair.
- Decide where on the canvas you want to place the Create Variable block and drag the port to that location.
- Select Create Variable.
- Enter the variable’s name. For example, enter millisecondsPerYear.
Group your blocks
- Press and hold the Command or Ctrl key.
- Click the blocks you want to group and click
Group selection.
- Hover over the group’s title, click
Edit title, and enter a name. For example, enter Milliseconds per year.
- Press the Return or Enter key.
Calculate the years since the milestone
Once you’ve created the variables you need to calculate the years since the milestone (now, date, and millisecondsPerYear), you can use them to get an answer.

Add an Evaluate block
Decide where on the canvas you want to place the Evaluate block and right-click that location. Then, select Evaluate.
Get the variables
- Click
Add data blocks and choose Get Variable.
- Enter the variable’s key and choose the variable. For example, if you want to add the now variable, enter now and select now.
- Repeat these steps for each variable.
Your Evaluate block will reference all the variables you created: now, date, and millisecondsPerYear.
Calculate
All Evaluate blocks default to Flows Query Language (FQL). You’ll use FQL to calculate the years since the milestone.
To calculate the value, add the following to the code editor:
This calculation takes the difference between now and the milestone date (which is in milliseconds) and divides it by milliseconds per year to get the years since the milestone. The FQL $floor() function removes any decimal values.
Optionally, use TypeScript to calculate this value. If you’d like to try this option, add another Evaluate block, switch to TypeScript (upper-right corner), and use the TypeScript Math.floor() method instead.
Connect an Output block
- Hover over the Evaluate block’s output port. The pointer changes to a crosshair.
- Decide where on the canvas you want to place the Display block and drag the port to that location.
- Select
Display.
Group your blocks
- Press and hold the Command or Ctrl key.
- Click the blocks you want to group and click
Group selection.
- Hover over the group’s title, click
Edit title, and enter a name. For example, enter Calculate years since milestone.
- Press the Return or Enter key.
Run the flow
From the canvas toolbar, click Run.

Congratulations! You calculated the years since a milestone and displayed the result in a Display block.