The online manual explains it here:

http://web2py.com/books/default/chapter/29/07/forms-and-validators#Date-and-time-validators

If I recall correctly, it may also be necessary to make an entry in your 
language dictionary. But try it first without such an entry.

On Monday, November 17, 2014 5:49:57 PM UTC-5, José Eloy wrote:
>
> Hi!
>
> I'm having troubles in making a query with 2 dates in SQL Server 2005.
>
> First, my table definition:
>
> db2.define_table('tabla_datos',
>                 Field('na', requires=IS_NOT_EMPTY()), 
>                 Field('fecha', 'datetime', requires=[IS_NOT_EMPTY(), 
> IS_DATETIME(format=T("%d/%m/%Y %H:%M:%S"), error_message='Debe ser 
> DD-MM-YYYY HH:MM:SS!')]),
>                 Field('ta', db2.tipos_de_asunto),
>                 Field('unidad',  requires=IS_NOT_EMPTY()),
>                 Field('operador'),
>                 Field('carta', requires=IS_NOT_EMPTY()),
>                 Field('importe', 'decimal(15,2)', requires=IS_NOT_EMPTY()),
>                 Field('observaciones') 
>                 )
>
> In my controller I receive from a form (via ajax) two dates for searching 
> in the database:
>
> def busca_consulta():
>
>     num_asunto = request.post_vars.input_na   
>     desde = request.post_vars.input_desde       # User write a date using 
> the Web2py widget. Format: %d/%m/%Y (time is not necessary)
>     hasta = request.post_vars.input_al               # User write a date 
> using the Web2py widget. Format: %d/%m%Y (time is not necessary)
>
>     rows= db2(((db2.tabla_datos.fecha>=desde) & 
> (db2.tabla_datos.fecha<=hasta)) & (db2.tabla_datos.na
> ==num_asunto)).select()
>  
> but I get error, Is it necessary to convert the variables "desde" and 
> "hasta" to datetime? How can I convert them?
>
> I've checked the SQL Server datetime format, the datetime is saved in the 
> records using the following format: %Y-%d-%m %H:%M:%S. I live in Mexico, 
> the format we use is: %d/%m/%Y %H:%M:%S
>
> My english is not very good, I hope you can understand me.
>
> Regards.
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to