Get Integer to Date

CREATE FUNCTION [dbo].[ufn_utl_GetDateToInteger]
(
    @Date DATETIME2
)
RETURNS INTEGER
AS

/*
Author: Mihir Shah
Modified Date: 03/07/2018
Purpose: Function to convert date to integer
Example:
select [dbo].[ufn_GetDateToInteger](StartTime) AS StartTimeInt from  [NDISBillCalc].[WorkSegments]
Output:
20180310
20180311
*/

BEGIN
    RETURN (CAST(CONVERT(VARCHAR(8), @Date, 112) AS INTEGER));
END;

GO

Comments

Popular posts from this blog

Calculating Age of the person in T-SQL

How to Troubleshoot Subscription issue in Reporting Services