SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- ======================================================
-- Author: <PROUD ,PRANAKHON RAJABHUTNUNIVERSITY>
-- Create date: <12 DEC 2009>
-- Description: <CREATE DATETIME WITH EXACTLY FORMAT>
-- ======================================================
CREATE FUNCTION [dbo].[DATE_SERIAL](@VAR_YEARPART INT ,@VAR_MONTHPART INT ,@VAR_DAYPART INT)
RETURNS DATETIME
AS
BEGIN
DECLARE
@TEMP_STR VARCHAR(20) ,
@RET_DATE DATETIME;
-- BEGIN CALCULATION
SET @TEMP_STR = CONVERT(VARCHAR ,@VAR_DAYPART) + '-'
+ CONVERT(VARCHAR ,@VAR_MONTHPART) + '-'
+ CONVERT(VARCHAR ,@VAR_YEARPART) ;
SET @RET_DATE = CONVERT(DATETIME ,@TEMP_STR ,105) ;
RETURN @RET_DATE ;
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Code (VB.NET)
-- =============================================
-- Author: <PROUD ,PRANAKHON RAJABHUT UNIVERSITY>
-- Create date: <11 MARCH 2010>
-- Description: <AS FUNCTION NAME>
-- =============================================
CREATE FUNCTION [dbo].[GET_LAST_DAY_OF_MONTH](@VAR_DATE DATETIME)
RETURNS DATETIME
AS
BEGIN
-- Declare the return variable here
DECLARE
@RET_DATE DATETIME ;
SET @RET_DATE = dbo.DATE_SERIAL(YEAR(@VAR_DATE),MONTH(@VAR_DATE),1 );
SET @RET_DATE = DATEADD( MONTH ,1 ,@RET_DATE );
SET @RET_DATE = DATEADD( DAY ,-1 ,@RET_DATE );
RETURN @RET_DATE
END
GO