1

I want to append 0 to my minute(mi) result returned by DATENAME function of sql server management studio.

select datename(mi,GETDATE())
  1. If the current time where 12:06:33.12(hh:mi:ss) then '6' would be returned by the above query and I want 0 to be prefixed with the result i.e '06' only when my minute is less than 10.

  2. This can be easily done by branching and checking the result obtained by above query and seeing if it is less than 10 i.e using a CASE statement.Is there a much cleaner way to do the job without branching?

1 Answer 1

1

You could do something like this:

SELECT RIGHT('00' + CONVERT(VARCHAR(2), datename(mi,GETDATE())), 2)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.