Introduction

In this article, we will create a User Defined Function that will accept the date of birth of the employee as a parameter and it will check if the given date is the last day of the month.

How to Create a User-Defined Function?

User-defined function to check if the given day is the last day of the month.

CREATEFUNCTIONCheckLastDay(@DoBDATETIME)
RETURNSBIT
AS
BEGIN
DECLARE@LastDayOfMonthDATETIME
DECLARE@ReturnValueBIT
SELECT@LastDayOfMonth =DATEADD(s,-1,DATEDIFF(m,0,@DoB)+1,0))
IF(DATEPART(dd,@LastDayOfMonth)=DATEPART(dd,@Dob))
BEGIN
SET@ReturnValue=1
END
ELSE
BEGIN
SET@ReturnValue=0
 END     
 RETURN@ReturnValue
END

Explanation