You can't really constrain the input of a UDF to a small set of values (to the best of my knowledge).
I would recommend creating a tabe for your enumerated values - something like this:
CREATE TABLE MyEnumTable (DatePartID tinyint, DatePartValue char(2))
GO
INSERT MyEnumTable(DatePartID, DatePartValue)
SELECT 1, 'yy'
UNION
SELECT 2, 'mm'
UNION
SELECT 3, 'dd'
UNION
SELECT 4, 'hh'
GO
CREATE FUNCTION MyDatePart(@IntervalType tinyint)
RETURNS varchar(255)
AS
BEGIN
IF NOT EXISTS (SELECT * FROM MyEnumTable WHERE DatePartID = @IntervalType)
RETURN 'Invalid IntervalType'
--Do your stuff
DECLARE @DatePartvalue char(2)
SELECT @DatePartValue = DatePartValue
FROM MyEnumTable
WHERE DatePartID = @IntervalType
RETURN @DatePartValue
END
GO
--Check it out
SELECT dbo.MyDatePart(3), dbo.MyDatePart(12)
Of course, my example is oversimplified, but you get the idea.
Also, consider making the function a table-valued function for performance reasons, if you're planning on using the udf in set statements. I blogged about the performance implications of various function types here:
http://thehobt.blogspot.com/2009/02/scalar-functions-vs-table-valued.html