How to construct a query with Web2py quantifying the difference between days

5

I'm using Web2py (Python), doing the query using DAL I wonder if it's possible to get the difference in days, something close to that

Example

#!/usr/bin/env python   
# -*- coding: utf-8 -*-

  resultado = db(
    (db.base_suporte.dt_solicitacao - db.base_suporte.dt_fechamento) >5
  ).select(db.base_suporte.dt_solicitacao)

out of curiosity the return of this query is

SELECT  base_suporte.dt_solicitacao FROM base_suporte WHERE (
    (base_suporte.dt_solicitacao - base_suporte.dt_fechamento) > 5.0);

I know how to do this using own commands from each database using db.executesql () , but would like a solution using the DAL engine so that it can maintain compatibility with other

I am using the individual processing of records as a workaround.

    
asked by anonymous 21.02.2015 / 03:07

1 answer

1

Isvaldo, I think what you want comes down to the following:

resultado = db(
        (db.base_suporte.dt_solicitacao - db.base_suporte.dt_fechamento) >5
      ).select(db.base_suporte.dt_solicitacao, db.base_suporte.dt_fechamento)

delta = db.base_suporte.dt_fechamento - db.base_suporte.dt_solicitacao
print delta.days

The return of any field of type datetime is a datetime object of python and the subtraction of two objects of this type, returns a timedelta equivalent to the subtraction of two dates and that has the days attribute, corresponding to int of difference.

    
19.05.2015 / 16:28