Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Formatting datetime2(3) value
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01681626
Message ID:
01681640
Views:
44
This message has been marked as a message which has helped to the initial question of the thread.
>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
"Navision is evil that needs to be erazed... to the ground"

Jabber: gorila@dione.zcu.cz
Jabber? Jabbim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform