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
  •  | 
  •  

Question

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

Était-ce utile?

La solution

You can use replace:

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

Autres conseils

Try this:

SELECT DATE_FORMAT(your_date, '%Y,%m,%d') FROM [...]
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top