Labels

Wednesday, April 3, 2013

Format



/*
This function format the input value based on the specified format and optional culture input.
If the culture value is not specified, then the language of the current session is used.
This can be used to format the numbers and datetime values into required format.
*/

DECLARE @CurrentDate DATETIME,
        @Format NVarchar(20),
        @Culture NVarchar(10)

SET @CurrentDate = GETDATE(); 
SET @Format = 'dd-MM-yyyy:hh:mm:ss'
SET @Culture =  'ar-LB'

-- SELECT CONVERT(VARCHAR(20), GETDATE(),101)

SELECT FORMAT(@CurrentDate,@Format, @Culture)  as Result

SELECT FORMAT(@CurrentDate,@Format)  as Result

No comments:

Post a Comment