Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread LIB - func - IsCurYear.sql
Mon, Feb 6 2012 8:58 AMPermanent Link

Lucian

CREATE FUNCTION "IsCurYear" (
IN "ADate" DATE)
RETURNS BOOLEAN
BEGIN
 DECLARE Result BOOLEAN DEFAULT False;
 DECLARE EndDate, StartDate DATE;
 DECLARE iYear INTEGER;

 SET EndDate = CURRENT_DATE;
 SET iYear = EXTRACT(YEAR, EndDate);
 SET StartDate = CAST(CAST(iYear AS VARCHAR) + '-01-01' AS DATE);

 IF ADate BETWEEN StartDate AND EndDate THEN
   SET Result = True;
 ELSE
   SET Result = False;
 END IF;

 RETURN Result;
END

DESCRIPTION 'Boolean function to return TRUE if the given date belongs to current year.'
Wed, Feb 8 2012 3:16 AMPermanent Link

David Cornelius

Cornelius Concepts

Avatar

This will do the same...

CREATE FUNCTION "IsCurYear" (IN "ADate" DATE)
RETURNS BOOLEAN
BEGIN
 RETURN (EXTRACT(YEAR FROM ADate) = EXTRACT(YEAR FROM CURRENT_DATE));
END

DESCRIPTION 'Boolean function to return TRUE if the given date belongs to
current year.'




David Cornelius
Cornelius Concepts
Wed, Feb 8 2012 7:28 AMPermanent Link

Lucian

>This will do the same...

I started I think with IsLastWeek or IsLastMonth, than blindly copy-pasted and adjusted it for the other utilities, without realising there's a simpler way Smile

Thank you for reviewing it, it's much better when it's simple!
Lucian
Image