Introduction:
Here I will explain how to get only month and year from date in sql server or extract only month and year from date time field in sql server.
Here I will explain how to get only month and year from date in sql server or extract only month and year from date time field in sql server.
Description:
In
previous articles I explained get time difference between two dates
in sql,
sql datediff function to show date
difference in days, difference between function and stored
procedures,
joins in SQL Server, substring function in SQL server
and many articles relating to SQL
server.
Now I will explain how to get only month and year from date in sql
server.
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
Output
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
3 comments :
good morning sir
please send me notes, example of normalization,Acid property,how to get data from database in gridviews
Thanks
Hi,
We can use following query to get Month & Year in SQL
SELECT DATENAME(MONTH, GETDATE()) + ' ' + DATENAME(YEAR, GETDATE())
how to know the year month and day from date of birth like 1986-08-10
Note: Only a member of this blog may post a comment.