---
schema_version: "1"
id: d699ba02fcb0909f87d61306ea109d883f3332cda55a4e523f19d0603df2b7f2
title: Calculate How Long Activities Take
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_saql/guides/concept/bi-saql-examples-daysbetween.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-examples-daysbetween.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 8a187c7ad4fa72af9932062ab437fe9aef7548d469a0a63f9bf2b97635a306d7
products:
  - Analytics SAQL Developer Guide
  - analytics
---

# Calculate How Long Activities Take

Use `daysBetween()` and `date_diff()` to calculate the difference between two dates or times.

## Example: Display the Number of Days Since an Opportunity Opened

Suppose that you have an opportunity dataset with the account name and the epoch seconds fields:

![Diagram showing the opportunity dataset.](https://developer.salesforce.com/media/bi_dev_guide_saql/bi_saql_date_opp_dataset.png)

You want to see how many days ago an opportunity was opened. Use `daysBetween()` and `now()`. Use `toDate()` to convert the order date epoch seconds to a date format that can be passed to `daysBetween()`.

```nolang
q = load "OpsDates1";

q = foreach q generate Account, daysBetween(toDate(OrderDate_sec_epoch), now()) as 'daysOpened';
```

The resulting data stream displays the number of days since the opportunity was opened.

![Diagram showing the number of days each account has been opened for.](https://developer.salesforce.com/media/bi_dev_guide_saql/bi_saql_date_daysopened.png)

## Example - How Many Weeks Did Each Opportunity Take to Close?

Use `date_diff()` with _datepart_ = `week` to calculate how long, in weeks, it took to close each opportunity.

```nolang
q = load "DTC_Opportunity";
q = foreach q generate date_diff("week", toDate(CreatedDate_sec_epoch), toDate(CloseDate_sec_epoch) ) as 'Weeks to Close';
q = order q by 'Weeks to Close';
```

**See Also**

- [daysBetween()](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/reference/bi-saql-functions-date-between.md)
- [date_diff()](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/reference/bi-saql-functions-date-diff.md)
