Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hello All,

I want to convert date time to Month/year like 09/11 in sql

Thanks
Posted
Comments
Herman<T>.Instance 15-Sep-11 6:15am    
what is the use of this question if you already had a solution?
AditSheth 15-Sep-11 6:36am    
I have not solution when i post this question. And then after i continue google search and try to get solution.When i got solution and see my Question i found better solution then mine..
Herman<T>.Instance 15-Sep-11 6:54am    
better start searching google ;)

1 solution

There are many ways like:

SQL
SELECT RIGHT(CONVERT(VARCHAR(8), GETDATE(), 3), 5) AS [MM/YY]


OR

SQL
SELECT SUBSTRING(CONVERT(VARCHAR(8), GETDATE(), 3), 4, 5) AS [MM/YY]
 
Share this answer
 
Comments
AditSheth 15-Sep-11 6:04am    
I did that as
select RIGHT('0' + CAST(DATEPART(Month, GETDATE()) AS varchar(2)),2) + '/' + Right(datepart(YYYY,GETDATE()),2) As [MM/YY]
but your answer is very simple
Thanks

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