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

String with dd-MM-yyyy hh:mm:ss format to datetime in SQL Server

I’m trying to convert a nvarchar(max) column to a datetime in SQL Server. The format is dd-MM-yyyy hh:mm:ss, which I’d like to keep, however I’d like to change the type to datetime. I’ve found many similar questions about this conversion, but not with my particular format.

I’ve tried CONVERT(nvarchar(MAX), string_column, 121), however without luck. How can this be done? As example, I’d like to convert the string 26-11-2021 08:19:16 to datetime.

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

>Solution :

 DECLARE @InString NVARCHAR(20)='26-11-2021 08:19:16';
 SELECT @InString;
 SELECT CONVERT(DATETIME,@InString,105);

Could you please try if it is suitable for you

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