Error doing query with between in datetime field

0

I'm trying to do a between but I do not know how to proceed.

where cliente.id = (select usuario.idCliente from usuario where usuario.login = 'julio') and
(cast(os.dataHora as date) between  '2016-09-08' and '2013-10-29')

or

where client.id = (select user.idClient from user where usuario.login = 'julio') and (os.dataHora between '2016-09-08' and '2013-10-29')

Error

    
asked by anonymous 07.11.2016 / 03:30

2 answers

1

Run in your database:

SET DATEFORMAT ymd;

The correct way is for you to change the language of your bank, so it will work in the default 'yyyy-mm-dd'.

If you want to use it the way it is, the format is:

yyyy-dd-mm hh:mi:ss.ms

To convert a String to date you can use any of the following commands:

cast('2016-11-07' as date);

or

convert(date, '2016-11-07');
    
07.11.2016 / 03:52
1

Operated using CONVERT where os.dataTime between CONVERT (datetime, '01 -08-2016 ', 105) and CONVERT (datetime, '30 -10-2016', 105)

    
07.11.2016 / 12:15