Converting a datetime to a date in database

(Sergi Almacellas Abellana) #1

Continuing the discussion from Search inside Dict:

The Cast function from python-sql can be used to convert from datetime (or timestampt) to date:

>>> from sql import Table, Cast
>>> t = Table('a')
>>> tuple(, 'DATE')))
('SELECT CAST("a"."date" AS DATE) FROM "a" AS "a"', ())

In tryton you can use sql_type function to determine the database type used to represent a field.

So inside tryton you can use:

Model = Pool().get('')
table = Model.__table__(),              

To select the value of the datetime field converted to the date field sql type.

Hope it helps