RaG
RaG

Reputation: 337

CONVERT/CAST Function not working for date conversion

Trying to convert date from string variable

DECLARE @start_date VARCHAR(max)
SET @start_date = '7/12/2020 9.00 AM'
CONVERT(DATETIME2, @start_date, 103)

Output :

Conversion Failed when Converting Date and/or Time from Character String

Also tried

CAST(@start_date AS DATETIME2(3))

Output :

Conversion Failed when Converting Date and/or Time from Character String

Need suggestion and resolution

Upvotes: 0

Views: 478

Answers (1)

sacse
sacse

Reputation: 3744

try the following:

SELECT CONVERT(DATETIME2, replace(@start_date, '.', ':'), 101) Converted

db<>fiddle

Upvotes: 2

Related Questions