sql server - Converting a nonstandard US datetime string to datetime in SQL -
i have dataset dates in format follows:
10/18/2007 8:00 a.m. 10/20/2007 10:00 a.m.
etc..
i'm having lot of trouble finding consistent query convert set of varchars in format datetime insertion datetime column. have tried many of convert styles (found here https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql) none works.
in sql server 2012 , up: each of these return null
when conversion fails instead of error.
declare @str varchar(32) = '10/20/2007 10:00 a.m.' select try_parse(replace(@str,'.m.','m') datetime using 'en-us')
returns: 2007-10-20 10:00:00
rextester demo: http://rextester.com/kwcf9843
Comments
Post a Comment