Tuesday, October 1, 2019

SQL Server - How to Get Only Month and Year From Date

To get only month and year from date in sql server we need to write the query like this


SELECT CONVERT(CHAR(4), yourdatecolumn, 100) + CONVERT(CHAR(4), yourdatecolumn, 120)FROM yourtablename
Example


SELECT CONVERT(CHAR(4), getdate(), 100) + CONVERT(CHAR(4), getdate(), 120)
Once we run above query we will get output like as shown below

Output


No comments:

Post a Comment

Get max value for identity column without a table scan

  You can use   IDENT_CURRENT   to look up the last identity value to be inserted, e.g. IDENT_CURRENT( 'MyTable' ) However, be caut...