How do I convert a date format in SQL to YYYY,MM,DD but with commas instead of forward slashes, full stops or dashes?

StackOverflow https://stackoverflow.com/questions/21380887

  •  03-10-2022
  •  | 
  •  

Pergunta

I need to get an output date format in SQL as YYYY,MM,DD, e.g. following example:

2014,03,10

I need there to be commas separating the integers, not dashes, forward slashes or full stops. I've already got the date sequence part right - SELECT CONVERT(VARCHAR(10), GETDATE(), 102) AS [YYYY,MM,DD] - but I need to replace the full stops with commas.

Thanks in advance for your help!

Jenny

Foi útil?

Solução

You can use replace:

SELECT replace(CONVERT(VARCHAR(10), GETDATE(), 102), '.', ',') AS [YYYY,MM,DD]

Outras dicas

Try this:

SELECT DATE_FORMAT(your_date, '%Y,%m,%d') FROM [...]
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top