Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
how to get month and year from date column in sql server 2014


Date
2016-01-15

how to get month and year in date column in sql server
Posted

 
Share this answer
 
Comments
iamvinod34 24-Jan-16 22:20pm    
this datepart() function separate separate will shown only date or month
but i want date and year display one column only..? how?
Hi, check this out

SQL
select   convert(char(4),year(getdate()))  + convert(char(4),month(getdate()))


hint: only characters could combine with + mark so we convert int to sting and combine
 
Share this answer
 
try out below SQL syntax
SQL
SELECT
   DATEADD(MONTH, DATEDIFF(MONTH, 0, <dateField>), 0) AS [year_month_date_field] FROM <your_table>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900