> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt. For full content including API reference and SDK examples, see https://learning.postman.com/llms-full.txt.

# 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:

1. Choose an existing workspace or [create a new one](/docs/collaborating-in-postman/using-workspaces/create-workspaces/).
2. Click **Flows > <img alt="Options icon" src="https://assets.postman.com/postman-docs/aether-icons/action-options-stroke.svg#icon" width="16px" /> More actions > 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.

<img alt="Now blocks" src="https://assets.postman.com/postman-docs/v11/postman-flows-now-v11-60.png" />

### Add a Now block

1. From the canvas toolbar, select <img alt="Add icon" src="https://assets.postman.com/postman-docs/aether-icons/action-add-stroke.svg#icon" width="16px" /> **Block**.
2. Click <img alt="Time icon" src="https://assets.postman.com/postman-docs/aether-icons/descriptive-time-stroke.svg#icon" width="16px" /> **Now**. If you want to search for the block, enter **Now** in search.
3. 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:

1. Hover over the **Now** block's output port. The pointer changes to a crosshair.
2. Decide where on the canvas you want to place the **Create Variable** block and drag the port to that location.
3. Click **Create Variable**. If you want to search for the block, enter **Create Variable** in search.
4. 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:

1. Press and hold the **Command** or **Ctrl** key.
2. Click the blocks you want to group. The canvas's flyout menu appears and displays the number of blocks you clicked.
3. Hover over the canvas's flyout menu and click <img alt="Folder icon" src="https://assets.postman.com/postman-docs/aether-icons/entity-folder-stroke.svg#icon" width="16px" /> **Group selection**.
4. Hover over the group's title and click <img alt="Edit icon" src="https://assets.postman.com/postman-docs/aether-icons/action-edit-stroke.svg#icon" width="16px" /> **Edit title**.
5. Enter a name. For example, enter **Now**.
6. 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.

![Milestone blocks](https://assets.postman.com/postman-docs/v11/postman-flows-record.jpg)

### Add a Record block

1. Decide where on the canvas you want to place the **Record** block and right-click that location.
2. Click <img alt="Record icon" src="https://assets.postman.com/postman-docs/aether-icons/descriptive-record-stroke.svg#icon" width="16px" /> **Record**. If you want to search for the block, enter **Record** in search.
3. Click <img alt="Add icon" src="https://assets.postman.com/postman-docs/aether-icons/action-add-stroke.svg#icon" width="16px" /> **Add data blocks** and select <img alt="String icon" src="https://assets.postman.com/postman-docs/aether-icons/descriptive-string-stroke.svg#icon" width="16px" /> **String**. If you want to search for the block, enter **String** in search.
4. Enter the string's key and value. For example, if the milestone is for a company, enter **company** and **Postman**, respectively.
5. Click <img alt="Add icon" src="https://assets.postman.com/postman-docs/aether-icons/action-add-stroke.svg#icon" width="16px" /> **Add data blocks** and select <img alt="Calendar icon" src="https://assets.postman.com/postman-docs/aether-icons/descriptive-calendar-stroke.svg#icon" width="16px" /> **Date**. If you want to search for the block, enter **Date** in search.
6. 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

1. Hover over the **Record** block's output port. The pointer changes to a crosshair.
2. Decide where on the canvas you want to place the **Select** block and drag the port to that location.
3. Select <img alt="Link icon" src="https://assets.postman.com/postman-docs/aether-icons/action-link-stroke.svg#icon" width="16px" /> **Select**. If you want to search for the block, enter **Select** in search.
4. 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

1. Hover over the **Select** block's output port. The pointer changes to a crosshair.
2. Decide where on the canvas you want to place the **Create Variable** block and drag the port to that location.
3. Select **Create Variable**. If you want to search for the block, enter **Create Variable** in search.
4. Enter the variable's name. For example, if the milestone is a company's founded date, enter **date**.

### Group your blocks

1. Press and hold the **Command** or **Ctrl** key.
2. Click the blocks you want to group and select <img alt="Folder icon" src="https://assets.postman.com/postman-docs/aether-icons/entity-folder-stroke.svg#icon" width="16px" /> **Group selection**.
3. Hover over the group's title, click <img alt="Edit icon" src="https://assets.postman.com/postman-docs/aether-icons/action-edit-stroke.svg#icon" width="16px" /> **Edit title**, and enter a name. For example, enter **Postman**.
4. 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.

<img src="https://assets.postman.com/postman-docs/v11/postman-flows-milliseconds-per-year-v11-60.png" alt="Milliseconds per year blocks" />

### Add an Evaluate block

1. Decide where on the canvas you want to place the **Evaluate** block and right-click that location.
2. Select <img alt="Code icon" src="https://assets.postman.com/postman-docs/aether-icons/descriptive-code-stroke.svg#icon" width="16px" /> **Evaluate**.
3. Add the following to the code editor:

   ```javascript
   1000 * 60 * 60 * 24 * 365.25
   ```

### Connect a Create Variable block

1. Hover over the **Evaluate** block's output port. The pointer changes to a crosshair.
2. Decide where on the canvas you want to place the **Create Variable** block and drag the port to that location.
3. Select **Create Variable**.
4. Enter the variable's name. For example, enter **millisecondsPerYear**.

### Group your blocks

1. Press and hold the **Command** or **Ctrl** key.
2. Click the blocks you want to group and click <img alt="Folder icon" src="https://assets.postman.com/postman-docs/aether-icons/entity-folder-stroke.svg#icon" width="16px" /> **Group selection**.
3. Hover over the group's title, click <img alt="Edit icon" src="https://assets.postman.com/postman-docs/aether-icons/action-edit-stroke.svg#icon" width="16px" /> **Edit title**, and enter a name. For example, enter **Milliseconds per year**.
4. 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.

![Calculate years since milestone blocks](https://assets.postman.com/postman-docs/v11/postman-flows-calculate-years-since-milestone-v11-60.png)

### Add an Evaluate block

Decide where on the canvas you want to place the **Evaluate** block and right-click that location. Then, select <img alt="Code icon" src="https://assets.postman.com/postman-docs/aether-icons/descriptive-code-stroke.svg#icon" width="16px" /> **Evaluate**.

### Get the variables

1. Click <img alt="Add icon" src="https://assets.postman.com/postman-docs/aether-icons/action-add-stroke.svg#icon" width="16px" /> **Add data blocks** and choose **Get Variable**.
2. Enter the variable's key and choose the variable. For example, if you want to add the **now** variable, enter **now** and select **now**.
3. 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](/docs/postman-flows/flows-query-language/introduction-to-fql/) (FQL). You'll use FQL to calculate the years since the milestone.

To calculate the value, add the following to the code editor:

```javascript
$floor(
	(now - date) /
	millisecondsPerYear
)
```

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

1. Hover over the **Evaluate** block's output port. The pointer changes to a crosshair.
2. Decide where on the canvas you want to place the **Display** block and drag the port to that location.
3. Select <img alt="Output icon" src="https://assets.postman.com/postman-docs/aether-icons/action-output-stroke.svg#icon" width="16px" /> **Display**.

### Group your blocks

1. Press and hold the **Command** or **Ctrl** key.
2. Click the blocks you want to group and click <img alt="Folder icon" src="https://assets.postman.com/postman-docs/aether-icons/entity-folder-stroke.svg#icon" width="16px" /> **Group selection**.
3. Hover over the group's title, click <img alt="Edit icon" src="https://assets.postman.com/postman-docs/aether-icons/action-edit-stroke.svg#icon" width="16px" /> **Edit title**, and enter a name. For example, enter **Calculate years since milestone**.
4. Press the **Return** or **Enter** key.

## Run the flow

From the canvas toolbar, click <img alt="Run icon" src="https://assets.postman.com/postman-docs/aether-icons/action-run-stroke.svg#icon" width="16px" /> **Run**.

![Calculate years since milestone flow](https://assets.postman.com/postman-docs/v11/postman-flows-calculate-years-since-milestone-complete.jpg)

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