Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Error trying to get a BETWEEN in a DateTime2 Column

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The Fecha column is of type DateTime2, if someone can help me please!

>Solution :

Your dates are not formatted for valid datetime2 parsing:

enter image description here

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading