Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-06-03 : 08:44:35
|
| Andrea writes "I have a field in sql server in format datetime that containsdates, i want to know how to extract the week of that dateEs. 2002-05-15week = 20but if i've a date of this type:2002-01-03i want a week of this typeweek = 02i want a '0' before the '2'thank you" |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-06-03 : 09:04:00
|
| You need to use a few functions, but it's pretty easy:SELECT Replace(Str(DatePart(wk, dateCol), 2, 0), ' ', '0')FROM myTableDatePart gets the week number, the Str function formats the number as 2 digits, with left-padded spaces, and the Replace function changes the spaces to zeros. |
 |
|
|
|
|
|