Calculating the time difference between two dates is a common task in clinical research. This can be useful for determining the time elapsed between visits, the age of patients at inclusion, or the duration of treatment. EasyMedStat provides an efficient way to perform this calculation using the `DateDiff`

formula. Follow these steps to calculate the time difference between two dates.

## Steps to Follow

### 1. Create a Numeric Variable

First, create a variable to store the result of your calculation.

- Go to the
**Variables menu** - Click
**"+ New Variable".** - Name your variable (e.g., "Time_Difference").
**Select "Numeric" as the variable type.**

### 2. Choose a "DateDiff" Formula

Next, select the `DateDiff`

formula from the available types.

- In the "Formulas" section,
**click "Edit Formula".** **Select "DateDiff"**from the list of available formulas.

### 3. Select the Start Date, End Date, and Unit

Specify the start date, end date, and unit of measure (days, months, or years).

**Start Date:**Choose the variable for the start date. This must be an Event variable.**End Date:**Choose the variable for the end date. This must be an Event variable.**Unit:**Select the unit (days, months, or years).

### 4. Verify the Outputs

Before activating the formula, verify its outputs using the examples calculated by the application based on already included patients, if available.

### 5. Activate the Formula

Finally, activate the formula so it applies to your data.

**Click "Save"**to save the formula.**Activate the formula**and ensure it applies correctly to the relevant variables.

## Example: Calculating Patient Age at Inclusion (in Years)

Let's use the example of calculating a patient's age at inclusion in a clinical study.

**Create a Numeric Variable**- Name:
`Age_at_Inclusion`

- Type: Numeric

- Name:
**Choose a "DateDiff" Formula**- Formula:
`DateDiff`

- Formula:
**Select the Start Date, End Date, and Unit**- Start Date:
`Date_of_Birth`

- End Date:
`Inclusion_Date`

- Unit:
`years`

- Start Date:
**Verify the Outputs**- Check the calculated examples provided by the application for accuracy.

**Activate the Formula**- Save and activate the
`Age_at_Inclusion`

formula.

- Save and activate the

For a patient born on January 1, 1980, and included in the study on January 1, 2020, the formula will calculate an age of 40 years.

Was this article helpful?

Thatâ€™s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Feedback sent

We appreciate your effort and will try to fix the article