# Using dates in table\_query() method

**URL:** <https://discuss.tryton.org/t/using-dates-in-table-query-method/725>\
**Category:** Developer\
**Created:** [September 12, 2018, 8:04am UTC](https://discuss.tryton.org/t/using-dates-in-table-query-method/725 "2018-09-12T08:04:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![khurram](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/khurram/32/263_2.png) [@khurram](https://discuss.tryton.org/u/khurram)\
**Post date:** [September 12, 2018, 8:04am UTC](https://discuss.tryton.org/t/using-dates-in-table-query-method/725/1 "2018-09-12T08:04:04Z")

</div>

Hi all,

I have overridden the table\_query() method of my model. I am using create\_date in where clause. Since the type of create\_date is ‘timestamp(6) without timezone’, how can I have the timezone adjustment applied on my queries.

For example, for I can see a record having create\_date “2018-09-09 19:03:21.944918” in database. The actual date with timezone ‘GMT+5’ will be '“2018-10-09 00:03:21.944918”. Now, when we search for records having create\_date ‘2018-09-09’, this record should not appear; but it is appearing in our search results. This is probably due to the reason that the timezone is not applied on this column. How can I update the where clause to apply timezone.

I am using create\_date as follows:  
where &= join00.right.create\_date \<= Transaction().context[‘end\_date’]

But, I want something like:  
where &= join00.right.create\_date + interval ‘5 hours’ \<= Transaction().context[‘end\_date’]

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [September 14, 2018, 6:23am UTC](https://discuss.tryton.org/t/using-dates-in-table-query-method/725/2 "2018-09-14T06:23:38Z")

</div>

I think it would be better to compare against a datetime instead of a date.  
datetime from the client are automatically converted into UTC and so you will work with a single timezone.

---

<div class="post-metadata">

**Author:** ![khurram](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/khurram/32/263_2.png) [@khurram](https://discuss.tryton.org/u/khurram)\
**Post date:** [September 14, 2018, 9:32am UTC](https://discuss.tryton.org/t/using-dates-in-table-query-method/725/3 "2018-09-14T09:32:21Z")

</div>

Sorry for the miscommunication. I am already comparing create\_date against a datetime. Actually we are searching for records having create\_date ‘2018-09-09 00:00:00’.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [September 14, 2018, 9:01pm UTC](https://discuss.tryton.org/t/using-dates-in-table-query-method/725/4 "2018-09-14T21:01:02Z")

</div>

Then you should use a datetime in UTC. If it comes from the client it will automatically be converted in UTC otherwise you as developer is responsible to always use UTC datetime.

---

<div class="post-metadata">

**Author:** ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)\
**Post date:** [October 14, 2018, 9:01pm UTC](https://discuss.tryton.org/t/using-dates-in-table-query-method/725/5 "2018-10-14T21:01:05Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
