Python 2.7 I'm having problems with the date format

I have a problem at the end of my request with dates

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

##chart excel advanced
import mysql.connector
import arrow
from xlsxwriter.workbook import Workbook
##/home/andrews/Downloads/GRAILS/tarjetasadicionales/web-app/tempFiles/
workbook = Workbook('output2.xlsx')
worksheet = workbook.add_worksheet()
##ADD A CHART SHEET
chartsheet = workbook.add_chartsheet()
conn = mysql.connector.connect(
         user='root',
         password='root',
         host='127.0.0.1',
         database='adicionales')


cur = conn.cursor()

##hire_start = arrow.get('2017-06-14 00:00:00')
##hire_start.format('YYYY-MM-DD HH:mm:ss ZZ')
##hire_end = arrow.get('2017-06-14 23:59:59')
##hire_end.format('YYYY-MM-DD HH:mm:ss ZZ')

query = ("""select
concat(substr(c.fecha_gestion, 9, 2),'/',substr(c.fecha_gestion, 6, 
2),'/',substr(c.fecha_gestion, 1, 4)) as 'Fecha Gestión'
, case substr(c.fecha_gestion, 6, 2)
when '01' then 'ENERO'
when '02' then 'FEBRERO'
when '03' then 'MARZO'
when '04' then 'ABRIL'
when '05' then 'MAYO'
when '06' then 'JUNIO'
when '07' then 'JULIO'
when '08' then 'AGOSTO'
when '09' then 'SEPTIEMBRE'
when '10' then 'OCTUBRE'
when '11' then 'NOVIEMBRE'
when '12' then 'DICIEMBRE'
else 'NO APLICA'
end as 'Mes Gestión'
, substr(c.fecha_gestion, 1, 4) as 'Año Gestión'
, concat(substr(c.fecha_gestion, 9, 2),'/',substr(c.fecha_gestion, 6, 
2),'/',substr(c.fecha_gestion, 1, 4)) as 'Fecha Consolidado'
, 'PLUS WIRELESS' as 'Nombre call center'
, upper(c.nombre_vendedor) as 'Usuario'
, 'CEDULA' as 'Tipo_Id'
, a.cedula as 'Id_adicional'
, upper(a.nacionalidad) as 'Nacionalidad'
, upper(a.primer_apellido) as 'Primer_apellido'
, upper(a.segundo_apellido) as 'Segundo_apellido'
, upper(a.primer_nombre) as 'Primer_nombre'
, upper(a.segundo_nombre) as 'Segundo_nombre'
, upper(a.nombre_tarjeta) as 'Nombre_tarjeta'
, a.fecha_nacimiento as 'Fecha_nacimiento'
, upper(a.sexo) as 'Sexo'
, upper(a.estado_civil) as 'Estado_civil'
, upper(a.parentesco) as 'Parentesco'
, upper(a.observaciones) as 'Observaciones'
, a.cupo_otorgado as 'Cupo'
, c.cuenta as 'Cuenta_titular'
, c.identificacion as 'Id_titular'
, upper(c.producto) as 'Producto'
, upper(concat(c.apellidos,' ',c.nombres)) as 'Nombre_completo_titular'
, upper(c.provincia_trab) as 'Provincia_trabajo'
, upper(c.ciudad_trab) as 'Ciudad_trabajo'
, upper(c.calle_principal_trab) as 'Avenida/Calle principal_trabajo'
, upper(c.numeracion_trab) as 'Numeración_trabajo'
, upper(c.calle_transversal_trab) as 'Calle_transversal_trabajo'
, upper(c.sector_trab) as 'Sector/Barrio_trabajo'
, upper(c.tipo_trab) as 'Casa_departamento_trabajo'
, upper(c.referencia_trab) as 'Referencia_trabajo'
, upper(concat(calle_principal_trab, ' ', numeracion_trab, ' ', 
calle_transversal_trab, ' ', sector_trab, ' ', referencia_trab)) as 
'Información_concatenada_trabajo'
, c.caracteres_trab as 'Caracteres_trabajo'
, upper(c.provincia_domic) as 'Provincia_domicilio'
, upper(c.ciudad_domic) as 'Ciudad_domicilio'
, upper(c.calle_principal_domic) as 'Avenida/Calle principal_domicilio'
, upper(c.numeracion_domic) as 'Numeración_domicilio'
, upper(c.calle_transversal_domic) as 'Calle_transversal_domicilio'
, upper(c.sector_domic) as 'Sector/Barrio_domicilio'
, upper(c.tipo_vivienda) as 'Casa_departamento_domicilio'
, upper(c.referencia_domic) as 'Referencia_domicilio'
, upper(concat(calle_principal_domic, ' ', numeracion_domic, ' ', 
calle_transversal_domic, ' ', sector_domic, ' ', referencia_domic)) as 
'Información_concatenada_trabajo'
, c.caracteres_dom as 'Caracteres_domicilio'
, upper(c.entrega) as 'Trabajo/Domicilio'
, upper(c.nombre_contacto) as 'Persona de contacto'
, upper(c.rango_visita) as 'Rango de visita'
, c.celular_contacto as 'Celular'
, c.telefono_trab_contacto as 'Telefono_trabajo'
, c.telefono_dom_contacto as 'Telefono_casa'
, c.estado_cta_digital as 'EmisionEstadoCtaDigital'
from clientes c, adicional a
where c.subestado_gestion_id in (select id from subestado where type = 
'Exitoso')
and c.id = a.clientes_id
and c.fecha_gestion between '2017-05-04 00:00:00' and '2017-05-08 
23:59:59'
""")

      

here i have a problem with date format '2017-05-04 00:00:00' and '2017-05-08 23:59:59' by deleting this line of code the query works and i can see the excel file and c.fecha_gestion between '2017-05-04 00:00:00' and '2017-05-08 23:59:59'

cur.execute(query)
results = cur.fetchall()
print(results)

chart = workbook.add_chart({'type': 'line'})
chartsheet.set_chart(chart)

for i, row in enumerate(results):
    for j, value in enumerate(row):
       worksheet.write(i, j, row[j])

# Insert the chart into the worksheet IN D1.
worksheet.insert_chart('Z1', chart)
##SHEET NUM AND THE VALUES TO COUNT FORM        
chart.add_series({'values': '=Sheet1!$B$1:$B$59649'})
workbook.close()

      

This is the database link

THIS IS THE DATABASE LINE

+3


source to share


1 answer


I ran the following query:

SELECT c.fecha_gestion FROM clientes c where c.id in (select a.clientes_id from adicional a) order by c.fecha_gestion asc 

      

The date range for c.fecha_gestion

was 2017-05-12 16:37:18

before 2017-06-13 09:49:00

.

All of them are greater than the maximum date 2017-05-08 23:59:59

specified in the instructions between

.

c.id = a.clientes_id

seems to restrict entries in clientes

for the date range you are requesting.



EDIT

Following are the results of running a query with a data dump without a clause between

, adding a column c.fecha_gestion

to the selected columns and using order by c.fecha_gestion asc

.

Look at the minimum value for the date c.fecha_gestion

, 2017-05-12 16:37:18

. Therefore, there are no rows with c.fecha_gestion

a value between 2017-05-04 00:00:00

and for this query 2017-05-08 23:59:59

, and therefore you are not getting any results with the condition between

:

query and results grid

0


source







All Articles