-2

How can we get the period from getdate() function in sql? I tried below SELECT CONVERT(VARCHAR(12), GETDATE(), 106) but this gives the result in dd mmm yyyy format. I want the result to be like 202009 (YYYYmm)

Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62
Sugandha Sharma
  • 55
  • 1
  • 1
  • 6

2 Answers2

0

Never mind. I found it Its

SELECT LEFT(CONVERT(varchar, GetDate(),112),6)
Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62
Sugandha Sharma
  • 55
  • 1
  • 1
  • 6
0

You can try these:

SELECT FORMAT(GETDATE(),'yyyyMM');

Or

SELECT CONVERT(CHAR(6), GETDATE(), 112);
Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62