SQL Server how to convert string and datetime value in sql

f0ofjuux  于 2023-02-18  发布在  其他
关注(0)|答案(2)|浏览(152)

I Have This Type Of Value
fe80::d235:a0ce:c3ce:b764%14:2/17/2023 12:29:34 PM

and I Want this Value As 02/17/2023 Using SQL

fivyi3re

fivyi3re1#

try?

DECLARE @TestString VARCHAR(100)
SET @TestString='fe80::d235:a0ce:c3ce:b764%14:2/17/2023 12:29:34 PM'
SELECT REPLACE(LEFT(REVERSE(LEFT(REVERSE(@TestString),LEN(@TestString)-CHARINDEX('/',@TestString)+3)),10),':','')
eeq64g8w

eeq64g8w2#

Here is an example to convert your string into a Date.

SELECT FORMAT(CONVERT(datetime, 'fe80::d235:a0ce:c3ce:b764%14:2/17/2023 12:29:34 PM'), 'MM/dd/yyyy') AS formatted_date;

相关问题