Example Two Digits Minutes Format using T-SQL
While using t-sql, it is common for sql developers that they require minutes format in 2 digit format.
I'll try to show you easiest method for two digits minutes formatting with sql example.
We will use DATEPART function in our example minutes formatting sql script.
Using DATEPART with MI (Minutes) argument, we can get the minutes value.
Later we had to convert the numeric DATEPART function output into a string variable using CONVERT or CAST string conversion function.
The last step is a string manipulation trick, by adding a zero string character and fetching the RIGHT part of the concatenated string.
DECLARE @Date DATETIME
SET @Date='20090909 09:00'
SELECT RIGHT('0' + CAST(DATEPART(MI,@date) AS Varchar(2)), 2)
SET @Date='20090909 09:09'
SELECT RIGHT('0' + CAST(DATEPART(MI,@date) AS Varchar(2)), 2)
SELECT RIGHT('0' + CAST(DATEPART(MI,GETDATE()) AS Varchar(2)), 2)
And the output of the above two digits minute format t-sql statement is as follows :