Sunday, February 19, 2012

Date conversion.

Is there a function I can use to retrieve the month and year of say getdate(
)?SELECT
DATEPART(MONTH, GETDATE()) [MonthColumn]
,DATEPART(YEAR, GETDATE()) [YearColumn]
,CAST(DATEPART(MONTH, GETDATE()) AS VARCHAR(2)) + '/' +
CAST(DATEPART(MONTH, GETDATE()) AS Char(4)) [MonthAndYear]
Simon Worth
Arul wrote:
> Is there a function I can use to retrieve the month and year of say getdate()?[/co
lor]|||Sorry, typo
SELECT
DATEPART(MONTH, GETDATE()) [MonthColumn]
,DATEPART(YEAR, GETDATE()) [YearColumn]
,CAST(DATEPART(MONTH, GETDATE()) AS VARCHAR(2)) + '/' +
CAST(DATEPART(YEAR, GETDATE()) AS Char(4)) [MonthAndYear]
Simon Worth
Simon Worth wrote:
> SELECT
> DATEPART(MONTH, GETDATE()) [MonthColumn]
> ,DATEPART(YEAR, GETDATE()) [YearColumn]
> ,CAST(DATEPART(MONTH, GETDATE()) AS VARCHAR(2)) + '/' +
> CAST(DATEPART(MONTH, GETDATE()) AS Char(4)) [MonthAndYear]
> Simon Worth
> Arul wrote:
>|||Did you get any error?
Madhivanan|||Did I get an error?
No.
SELECT
DATEPART(MONTH, GETDATE()) [MonthColumn]
,DATEPART(YEAR, GETDATE()) [YearColumn]
,CAST(DATEPART(MONTH, GETDATE()) AS VARCHAR(2)) + '/' +
CAST(DATEPART(YEAR, GETDATE()) AS Char(4)) [MonthAndYear]
MonthColumn,YearColumn,MonthAndYear
3,2005,3/2005
(1 row(s) affected)
Simon Worth
Madhivanan wrote:
> Did you get any error?
> Madhivanan
>

No comments:

Post a Comment