Skip to content
Advertisement

Change date time format from YYY-MM-DD HH:MM:SS to YYYY.MM.DD HH:MM:SS in SQL Server

I have a table with a column RequestDate with following format 2019-12-01 00:00:00:000. I want to see results like this: 2019.12.01 00:00:00:000.

I used this command

SELECT CONVERT(char(10), RequestDate, 104) AS finaldate

From the above query I am seeing results as 2019.12.01, but I am missing time (00:00:00:000) – how can I keep along with time. I want final results like 2019.12.01 00:00:00:000

Advertisement

Answer

I don’t think that there is a built-in format specifier for this. But you could do:

replace(convert(varchar, requestDate, 121), '-', '.')

121 gives you format YYYY-MM-DD HH:MM:SS.SSS. You can then replace each occurence of '-' with ':'.

Note that this assumes that you have a datetime datatype to start with. If you have a string, then no need to convert(), you can just replace().

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement