Skip to content
Advertisement

How can i get a zero in front of the week number when it is a one-digit number?

I want to get the week number, and I did using DATEPAR(WEEK,DATE) , however, one-digit week numbers do not come with a zero in front.

Basically I need to get 01, 02, 03 instead of 1, 2, 3.

Advertisement

Answer

In SQL Server, you can left pad with this logic:

select right('0' + datename(week, date), 2)
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement