# How to use Postgres date\_trunc via CriteriaApi in Hibernate 6

**URL:** <https://discourse.hibernate.org/t/how-to-use-postgres-date-trunc-via-criteriaapi-in-hibernate-6/7220>\
**Category:** Hibernate ORM\
**Created:** [February 2, 2023, 7:54am UTC](https://discourse.hibernate.org/t/how-to-use-postgres-date-trunc-via-criteriaapi-in-hibernate-6/7220 "2023-02-02T07:54:27Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [February 2, 2023, 2:07pm UTC](https://discourse.hibernate.org/t/how-to-use-postgres-date-trunc-via-criteriaapi-in-hibernate-6/7220/2 "2023-02-02T14:07:11Z")

</div>

You can pass  
` new SqmExtractUnit<>( TemporalUnit.DAY, ((NodeBuilder) cb).getIntegerType(), (NodeBuilder) cb )` instead of `cb.literal("day")`. We don’t have an API yet for constructing such extract and duration units, but ultimately I envision a method in `HibernateCriteriaBuilder` to invoke the `date_trunc` function.

---

_[View the full topic](https://discourse.hibernate.org/t/how-to-use-postgres-date-trunc-via-criteriaapi-in-hibernate-6/7220)._
