Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

force 2 digit week numbers 2

Status
Not open for further replies.

jonhowe

MIS
Apr 7, 2004
21
0
0
GB
Any ideas on a more elegant way to generate a 2 digit week number i.e. in the range 01-54 than:

select REPLICATE('0',2-len(DATENAME(ww,datefield))) + DATENAME(ww,datefield)

I must have 01, 02 etc not 1,2 etc for weeks < 10.


 
Slightly more elegant:

select right( '00' + datename(ww, datefield), 2 )
 
yes, that looks better, and I could turn it into a UDF, so that it became
select dbo.myweek(datefield) ...
 
Don't turn it into a UDF unless you don't mind a performance penalty of about 20%.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top