You can use the STUFF() method to insert characters into your string to format it in to a value SQL Server will be able to understand:

DECLARE @datestring NVARCHAR(20) = '20120225143620'

-- desired format: '20120225 14:36:20'
SET @datestring = STUFF(STUFF(STUFF(@datestring,13,0,':'),11,0,':'),9,0,' ')

SELECT CONVERT(DATETIME, @datestring) AS FormattedDate

Output:

FormattedDate
=======================
2012-02-25 14:36:20.000

This approach will work if your string is always the same length and format, and it works from the end of the string to the start to produce a value in this format: YYYYMMDD HH:MM:SS

For this, you don't need to separate the date portion in anyway, as SQL Server will be able to understand it as it's formatted.

Related Reading:

STUFF (Transact-SQL)

The STUFF function inserts a string into another string. It deletes a specified length of characters in the first string at the start position and then inserts the second string into the first string at the start position.

STUFF ( character_expression , start , length , replaceWith_expression )

Answer from Tanner on Stack Overflow
Discussions

how can i convert 'yyyymmddhhmmss' to datetime - SQL Server Forums
Microsoft SQL Server articles, forums and blogs for database administrators (DBA) and developers. More on sqlteam.com
๐ŸŒ sqlteam.com
July 15, 2010
Adding YYYYMMDD and HHMMSS to get mm/dd/yyyy HH:MM:SS โ€“ SQLServerCentral Forums
Adding YYYYMMDD and HHMMSS to get mm/dd/yyyy HH:MM:SS Forum โ€“ Learn more on SQLServerCentral More on sqlservercentral.com
๐ŸŒ sqlservercentral.com
June 12, 2014
Date format YYYYMMDDHHMMSS - Databases & Queries - Spiceworks Community
Dear Everyone Can somebody help me to convert a date/time values into a format YYYYMMDDHHMMSS Currently, when we select current date, it would result to:- 2005-02-08 15:15:34.247 We would like if possible to have the output formatted without the โ€œโ€-โ€œโ€ & โ€œโ€:โ€œโ€. Though we can ... More on community.spiceworks.com
๐ŸŒ community.spiceworks.com
0
February 8, 2005
How to get YYYYMMDDHHMMSS โ€“ SQLServerCentral Forums
How to get YYYYMMDDHHMMSS Forum โ€“ Learn more on SQLServerCentral More on sqlservercentral.com
๐ŸŒ sqlservercentral.com
October 21, 2021
๐ŸŒ
MSSQLTips
mssqltips.com โ€บ home โ€บ sql date format examples using convert function
SQL Date Format Examples using SQL CONVERT Function
September 26, 2025 - --SELECT a datetime column as a string formatted dd/mm/yyyy (4 digit year) SELECT TOP 3 CONVERT(CHAR(10), ExpectedDeliveryDate, 103) ExpectedDeliveryDateFormattedAsText FROM Purchasing.PurchaseOrders WHERE OrderDate < @Datetime; --SELECT a datetime column as a string formatted dd/mm/yy (2 digit year) SELECT TOP 3 CONVERT(CHAR(8), ExpectedDeliveryDate, 3) ExpectedDeliveryDateFormattedAsText FROM Purchasing.PurchaseOrders WHERE OrderDate < @Datetime; Once the query runs, review SQL CONVERT output as shown below.
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ sql โ€บ t-sql โ€บ functions โ€บ cast-and-convert-transact-sql
CAST and CONVERT (Transact-SQL) - SQL Server | Microsoft Learn
SQL Server returns an error message when converting nonnumeric char, nchar, nvarchar, or varchar data to decimal, float, int, numeric. SQL Server also returns an error when an empty string (" ") is converted to numeric or decimal. The styles for which the string-to-datetime conversion is nondeterministic are as follows:
๐ŸŒ
Databricks Community
community.databricks.com โ€บ t5 โ€บ data-engineering โ€บ string-converstion-to-datetimestamp-format โ€บ td-p โ€บ 27940
Solved: String converstion to datetimestamp format - Databricks Community - 27940
October 12, 2022 - 1) what expression i can use to ...nguage-manual/sql-ref-datetime-pattern.html#pat... spark.sql("select date_format(to_timestamp(concat('20221009','010911'),'yyyyMMddHHmmss'),'yyyy-MM-dd hh:mm:ss a') as my_date").display()...
๐ŸŒ
SQL Team
sqlteam.com โ€บ forums โ€บ topic.asp
how can i convert 'yyyymmddhhmmss' to datetime - SQL Server Forums
July 15, 2010 - Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Find elsewhere
๐ŸŒ
Spiceworks
community.spiceworks.com โ€บ programming & development โ€บ databases & queries
Date format YYYYMMDDHHMMSS - Databases & Queries - Spiceworks Community
February 8, 2005 - Dear Everyone Can somebody help ... without the โ€œโ€-โ€œโ€ & โ€œโ€:โ€œโ€. Though we can only do this:- select CONVERT(char(8), getdate(), 112) & would result to 20050208....
๐ŸŒ
SQL Shack
sqlshack.com โ€บ sql-convert-date-functions-and-formats
SQL Convert Date functions and formats
May 21, 2021 - Similarly, lets us add 1 year to current date using the following query. We can combine the SQL DATEADD and CONVERT functions to get output in desired DateTime formats. Suppose, in the previous example; we want a date format in of MMM DD, YYYY.
๐ŸŒ
SQLServerCentral
sqlservercentral.com โ€บ forums โ€บ topic โ€บ how-to-get-yyyymmddhhmmss
How to get YYYYMMDDHHMMSS โ€“ SQLServerCentral Forums
October 21, 2021 - SELECT YYYYMMDDHHMISS = CONVERT(CHAR(14), CONVERT(BIGINT,CONVERT(CHAR(8),GETDATE(),112))*1000000 +DATEPART(hh,GETDATE())*10000 +DATEPART(mi,GETDATE())*100 +DATEPART(ss,GETDATE()) ) ; Yeah... I know what a lot of folks are thinking. "Big deal! 3.6 seconds v.s. 10.4 on 10 MILLION rows!
๐ŸŒ
Codesenior
codesenior.com โ€บ sources โ€บ docs โ€บ tutorials โ€บ How-to-convert-YYYYMMDDHHMMSS-to-Datetime-in-Microsoft-Sql-Server.pdf pdf
How to convert YYYYMMDDHHMMSS to Datetime in Microsoft Sql Server
How to convert YYYYMMDDHHMMSS to Datetime in Microsoft Sql Server ยท To convert yyyymmddhhmmss string format to datetime in Microsoft Sql Server, you can use below sql script:
๐ŸŒ
SQL Shack
sqlshack.com โ€บ sql-server-functions-for-converting-string-to-date
SQL Server functions for converting a String to a Date
May 21, 2021 - Explicit where conversions are visible to the user and they are performed using CAST or CONVERT functions or other tools ยท In this article, we will explain how a string to date conversion can be achieved implicitly, or explicitly in SQL Server using built-in functions such as CAST(), TRY_CAST(), CONVERT(), TRY_CONVERT() and TRY_PARSE().
๐ŸŒ
Google Cloud
googlecloudcommunity.com โ€บ looker โ€บ q&a โ€บ looker
Solved: Re: How to convert string to timestamp in looker
April 1, 2022 - Hi team, We have date string as 20210131120101(YYYYMMDDhhmmss) in table. We want to interpret this string into timestamp so looker can treat it as time stamp. Then we want to extract date parts from 20210131120101: 20โ€ฆ
๐ŸŒ
Databricks Community
community.databricks.com โ€บ t5 โ€บ data-engineering โ€บ convert-date-to-yyyymmdd-in-databricks-sql โ€บ td-p โ€บ 13160
Solved: Convert Date to YYYYMMDD in databricks sql - Databricks Community - 13160
April 10, 2024 - ... basically with to_date() and date_format() you can play with dates all you want. to_date converts a string to a date (with the format the datestring is in as a parameter), and date_format converts a date to a string (with the format the output has to be in as a parameter).
๐ŸŒ
Oracle
forums.oracle.com โ€บ ords โ€บ apexds โ€บ post โ€บ how-to-convert-datetime-to-yyyy-mm-ddthh-mi-ss-000-0000-so-2375
How to convert DateTime to YYYY-MM-DDTHH:MI:SS.000+0000 so that I can get records from table - Oracle Forums
April 28, 2021 - Hi, I looking for a help in converting the Timestamp to a string in the format YYYY-MM-DDTHH:MI:SS.000+0000 Background: I have a column Opt_Out_Time defined as a string and that stores the values in &...
๐ŸŒ
Informatica Network
network.informatica.com โ€บ s โ€บ question โ€บ 0D56S0000AD70FbSQJ โ€บ help-to-convert-string-into-date
help to convert string into date
Loading ยท ร—Sorry to interrupt ยท Refresh ยท Actions ยท Ask a Question ยท Contact Support ยท Terms of Use ยท Trademarks ยท Question Detail
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ dotnet โ€บ standard โ€บ base-types โ€บ custom-date-and-time-format-strings
Custom date and time format strings - .NET | Microsoft Learn
Dim thisDate1 As Date = #6/10/2011# Console.WriteLine("Today is " + thisDate1.ToString("MMMM dd, yyyy") + ".") Dim thisDate2 As New DateTimeOffset(2011, 6, 10, 15, 24, 16, TimeSpan.Zero) Console.WriteLine("The current date and time: {0:MM/dd/yy H:mm:ss zzz}", thisDate2) ' The example displays the following output: ' Today is June 10, 2011. ' The current date and time: 06/10/11 15:24:16 +00:00 ยท In parsing operations, custom date and time format strings can be used with the DateTime.ParseExact, DateTime.TryParseExact, DateTimeOffset.ParseExact, and DateTimeOffset.TryParseExact methods.