# Datediff

Calculates the difference between two date, time, or timestamp expressions based on the date or time part requested. Difference is calculated as date\_1 - date\_2.

## Parameters

| Name       | Type         | Description                                                                                                                                                               | Is Optional |
| ---------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| date\_part | date\_part   | Must be one of the values listed in [Supported Date and Time Parts](https://docs.snowflake.com/en/sql-reference/functions-date-time.html#label-supported-date-time-parts) |             |
| date\_1    | mixed\_value | Starting date. Can be a date column, date, time, or timestamp.                                                                                                            |             |
| date\_2    | mixed\_value | Date to subtract from date\_1. Can be a date column, date, time, or timestamp.                                                                                            |             |
| alias      | value        | Name for the new column created by the datediff.                                                                                                                          | True        |

## Example

```python
ds = rasgo.get.dataset(id)

ds2 = ds.datediff(date_part='year', date_1='END_DATE', date_2="'2022-01-01'")
ds2.preview()
```

## Source Code

{% embed url="<https://github.com/rasgointelligence/RasgoTransforms/blob/main/rasgotransforms/rasgotransforms/transforms/datediff/snowflake/datediff.sql>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.rasgoml.com/rasgo-docs/rasgo-0.1/all-transforms/datediff.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
