1
I need to filter a query of every client who has a birthday between two informed dates. How can I make a comparison of dates disregarding the year registered with the client?
The current consultation is like this:
Parameters informed: Start Date:29/04, End Date:05/05
Where Convert(datetime,
Convert(varchar, DAY(cli.DataNascimento)) + '/' +
convert(varchar, MONTH(cli.DataNascimento)) + '/1900', 103)
>= convert(datetime, '29/04/1900', 103)
And Convert(datetime,
Convert(varchar, DAY(cli.DataNascimento)) + '/' +
convert(varchar, MONTH(cli.DataNascimento)) + '/1900', 103)
<= convert(datetime, '05/05/1900', 103)
But this query is returning the following error:
Mensagem 242, Nível 16, Estado 3, Linha 1
A conversão de um tipo de dados varchar em um tipo de dados datetime resultou em um valor fora do intervalo.
Is there any better way to do this consultation?
How do you know that greater date should be in the year 1900?
– Caique Romero
All dates will be in the year 1900 because I don’t want to consider the year, so I convert all dates to the same year
– Pilati
Don’t post 'Solution' on a question, I don’t think it makes sense.
– Diego Rafael Souza
How is the Databirth: date, datetime column declared? // If declared as datetime, the hours part is zeroed?
– José Diz