Server Type: MSSQL 2014
My string(s): VARCHAR '2/05/2017 7:54:51 PM'
I need to convert that to any supported DateTime format (or preferably directly to epoch). It needs to handle NULL and "" (blank) rows.
I've spent a good few hours trawling answers and Google to no avail. The frustrating bit is the stored format is only slightly different to Date Format 131.
I've tried things such as;
FORMAT(CONVERT(DATETIME, '2/05/2017 7:54:51 PM'), 'dd/MM/yyyy hh:mm:ss')
CONVERT(DATETIME, '2/05/2017 7:54:51 PM',22)
CONVERT(DATETIME, '2/05/2017 7:54:51 PM',131)
/* SQL Error (241): Conversion failed when converting date and/or time from character string. */
/* SQL Error (242): The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. */
As well as a whole bunch of muck-arounds with SUBSTRING/CHARINDEX and so on to try and handle each part individually, to no avail.