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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 QUESTION ABOUT FORMATTING DATE

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 contains
dates, i want to know how to extract the week of that date

Es. 2002-05-15
week = 20

but if i've a date of this type:
2002-01-03

i want a week of this type

week = 02

i 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 myTable


DatePart 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.

Go to Top of Page
   

- Advertisement -