Friday, February 24, 2012

DatePart Function

Hi,

I'm curren't writing a stored procedure for my sql server express database and need to display the year part of a date field as '04' but using the DatePart function it will only display as '2004'? Is it possible to get the Year part of the date to display showing the last 2 digits of the Year only? I don't require another part of the date field just the Year part. All help is well come.

Code been used is shown below:

DATEPART(yy,[Date])

Hi,

The datepart function doesn't have an argument to do this. You can do the following to get the desired result:

SELECT RIGHT(DATEPART(yy, [Date]), 2)

Greetz,

Geert

Geert Verhoeven
Consultant @. Ausy Belgium

My Personal Blog

|||Thanks Geert it worked a treat!!

No comments:

Post a Comment