# Datetrunc

Truncates a date to the datepart you specify. For example, if you truncate the date '10-31-2022' to the 'month', you would get '10-1-2022'.

For a list of valid dateparts, refer to [Supported Date and Time Parts](https://docs.snowflake.com/en/sql-reference/functions-date-time.html#label-supported-date-time-parts)

## Parameters

| Name  | Type           | Description                                                                                                | Is Optional |
| ----- | -------------- | ---------------------------------------------------------------------------------------------------------- | ----------- |
| dates | datepart\_dict | dict where the keys are names of column(s) you want to datetrunc and the values are the desired date grain |             |

## Example

Pull a source Dataset and preview it:

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

|    | DATE       |  FIPS | COVID\_NEW\_CONFIRMED |
| -: | ---------- | ----: | --------------------: |
|  0 | 2020-10-17 | 47183 |                    12 |
|  1 | 2020-10-18 | 47183 |                    13 |
|  2 | 2020-10-19 | 47183 |                     5 |
|  3 | 2020-10-20 | 47183 |                    10 |
|  4 | 2020-10-21 | 47183 |                     9 |
|  5 | 2020-10-22 | 47183 |                    14 |
|  6 | 2020-10-23 | 47183 |                    44 |
|  7 | 2020-10-24 | 47183 |                    12 |
|  8 | 2020-10-25 | 47183 |                    38 |
|  9 | 2020-10-26 | 47183 |                    12 |

Transform the Dataset and preview the result:

```python
ds2 = ds.datetrunc(
  dates = {
    'DATE':'month',
    'Timestamp':'hour'
  }
)

ds2.preview()

```

|    | DATE       |  FIPS | COVID\_NEW\_CONFIRMED | DATE\_MONTH |
| -: | ---------- | ----: | --------------------: | ----------- |
|  0 | 2020-10-17 | 47183 |                    12 | 2020-10-01  |
|  1 | 2020-10-18 | 47183 |                    13 | 2020-10-01  |
|  2 | 2020-10-19 | 47183 |                     5 | 2020-10-01  |
|  3 | 2020-10-20 | 47183 |                    10 | 2020-10-01  |
|  4 | 2020-10-21 | 47183 |                     9 | 2020-10-01  |
|  5 | 2020-10-22 | 47183 |                    14 | 2020-10-01  |
|  6 | 2020-10-23 | 47183 |                    44 | 2020-10-01  |
|  7 | 2020-10-24 | 47183 |                    12 | 2020-10-01  |
|  8 | 2020-10-25 | 47183 |                    38 | 2020-10-01  |
|  9 | 2020-10-26 | 47183 |                    12 | 2020-10-01  |

## Source Code

{% embed url="<https://github.com/rasgointelligence/RasgoTransforms/blob/main/rasgotransforms/rasgotransforms/transforms/datetrunc/snowflake/datetrunc.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/datetrunc.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.
