Dario Federici Dario Federici - 1 year ago 89
SQL Question

TSQL DatePart Week in ww format 01 instead of 1

What is the best way to get the week from a date in the format 01 02 03 04 05 rather than 1 2 3 4 5?

Answer Source

The simplest method is to concatenate your leading 0s and then taking the two rightmost values:

select right(concat('00', DATEPART(week, getdate())), 2) as WeekNum

You do not need a udf for this...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download