I am trying to filter a SQL database using BETWEEN:
SELECT *
FROM RegistroCaja
WHERE Fecha BETWEEN CONVERT(datetime2, '15/12/2021 08:54:33')
AND CONVERT(datetime2, '17/12/2021 08:54:34')
But I get this error:
Conversion failed when converting date and/or time from character string.
The Fecha column is of type DateTime2, if someone can help me please!
>Solution :
Your dates are not formatted for valid datetime2 parsing:
See https://docs.microsoft.com/en-us/sql/t-sql/data-types/datetime2-transact-sql?view=sql-server-ver15 for more information. But switch the day with the month and you should be able to do the conversion.
