def make_date_span(engine, interval, field):
    FUNCTIONS_FOR_ENGINES = {
        "mysql": "UNIX_TIMESTAMP(`{field}`), UNIX_TIMESTAMP(DATE_ADD(`{field}`, INTERVAL 1 {interval}))",
        "postgresql": "EXTRACT(EPOCH FROM ({field}::date)), EXTRACT(EPOCH FROM ({field}::date + INTERVAL '1 {interval}'))"
    }

    if engine not in FUNCTIONS_FOR_ENGINES:
        raise NotSupportedError('Database engine %s is not supported' % engine)

    template = FUNCTIONS_FOR_ENGINES[engine]
    return template.format(field=field, interval=interval)
Returns start and end of timeframe for given duration:
dataset/ETHPy150Open opennode/nodeconductor/nodeconductor/monitoring/zabbix/sql_utils.py/make_date_span