question

529992 avatar image
529992 asked

How can I convert SQL Server date to custom formats

SELECT GETDATE() AS CurrentDateTime 2015-08-30 19:22:24.830 I need this output (in SQL Server) 2015-08-30 19 2015-08
sql-serverformatting
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
You have several answers below. For each of those answers that are helpful you should click on the thumbs up next to the answers so that it turns green. If any one of the answers below lead to a solution to your problem, click on the check mark next to that one answer so that it turns green. This web site works best if you do the voting and marking of answers so that the next person who looks at your question knows what the solution was.
0 Likes 0 ·
Sakthivel avatar image
Sakthivel answered
Hi, Can you try this following query SELECT RIGHT(CONVERT(VARCHAR(10), GETDATE(), 105), 7) AS [MM-YYYY]
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

KenJ avatar image KenJ commented ·
@Sakthivel - run your query real quick and compare the format of the output to what the OP is looking for
1 Like 1 ·
KenJ avatar image
KenJ answered
We had a question almost exactly like this last week - [ https://ask.sqlservercentral.com/questions/127393/how-to-get-the-date-value-like-20152807-150000-wit.html][1] You will need to make use of the convert function to format your date - [ https://msdn.microsoft.com/en-us/library/ms187928.aspx][2] To get the date with just the hour, try this: select left(convert(varchar, getdate(), 120), 13) Getting the year-month is a simple tweak to that. [1]: https://ask.sqlservercentral.com/questions/127393/how-to-get-the-date-value-like-20152807-150000-wit.html [2]: https://msdn.microsoft.com/en-us/library/ms187928.aspx
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.