>Hi everybody,
>
>I've been trying to find some help online as how to get the desired result and could not.
>
>I want to format the datetime2(3) value this way (say, the value is '2019-08-23 13:00:00.000') and I want to format it as
>'20190823_130000.000' using format function and I can not figure out how to do the very last part of correctly showing milliseconds.
>
>Also, I want to be able to do the opposite operation, e.g. from the character value shown in the format above I want to construct the datetime2(3) value correctly. I do have code using several substring which I created, but I was thinking if there is a more efficient and simple way?
>
>Thanks in advance.
Hi,
select stuff(replace(replace(convert(varchar(30), getdate(), 126),':',''),'-',''), 9, 1, '_')
MartinaJ