May 19, 2009 at 6:19 am
Hi,
How to retreive only month and year from datetime colomn. (dd/mm/yy mm:ss:xx)
any help or any comment will be highly appreciated.
May 19, 2009 at 6:26 am
SELECT YEAR( GETDATE() ) AS [Year], MONTH( GETDATE() ) AS [Month]
--Ramesh
May 19, 2009 at 9:25 am
All of these get just the month / year in different ways, and with different formatting:
declare @Date datetime = GetDate()
select MONTH(@date), YEAR(@date)
select DATEPART(month, @Date), DATEPART(year, @Date)
select CONVERT(char(6), @Date, 112)
select CONVERT(char(7), @Date, 102)
select RIGHT(convert(char(10),@Date, 103), 7)
select RIGHT(convert(char(10),@Date, 104), 7)
select RIGHT(convert(char(10),@Date, 105), 7)
select LEFT(convert(char(10), @Date, 111), 7)
select LEFT(convert(char(10), @Date, 120), 7)
select LEFT(convert(char(10), @Date, 121), 7)
select LEFT(convert(char(10), @Date, 126), 7)
select LEFT(convert(char(10), @Date, 127), 7)
select LEFT(convert(char(10), @Date, 112), 6)
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
May 19, 2009 at 10:02 am
Hi,
great thanks for your help.
It works perfectly:cool::cool::cool:
Kind regards.
May 19, 2009 at 10:02 am
Hi,
great thanks for your help.
It works perfectly:cool::cool::cool:
Kind regards.
May 19, 2009 at 10:02 am
Hi,
great thanks for your help.
It works perfectly:cool::cool::cool:
Kind regards.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply