2015-04-11

TSQL - Get dayID, a date in the format YYYYMMDD

/*

       -- Execution
       select dbo.getDayID( '1/31/2012' );
       select dbo.getDayID( cast('1/31/2012' as date) );


*/
ALTER function [dbo].[getDayID](
       @PeriodDate date
)
returns bigint
as
begin

       return(
              ( year( @PeriodDate ) * 10000 )
              + ( month( @PeriodDate ) * 100 )
              + day(@PeriodDate)
       );

end
;


No comments:

Post a Comment