Tuesday, March 20, 2012

Convert Week into Start and End Date

Some of our sales data is a w/year format like this...
SELECT DATEPART(wk, GETDATE()) AS 'W', DATEPART(yy, GETDATE()) AS 'Year'
I would lie to convert it to mm/dd/yy Start - mm/dd/yy End date.
Thanks!Ken,
Try:
SELECT CONVERT(VARCHAR(10),GETDATE(),1), CONVERT(VARCHAR(10),GETDATE(),101)
HTH
Jerry
"Ken" <Ken@.discussions.microsoft.com> wrote in message
news:432262B5-4392-4107-9A1A-182494C7F896@.microsoft.com...
> Some of our sales data is a w/year format like this...
> SELECT DATEPART(wk, GETDATE()) AS 'W', DATEPART(yy, GETDATE()) AS
> 'Year'
> I would lie to convert it to mm/dd/yy Start - mm/dd/yy End date.
> Thanks!
>|||Create a Calendar table and join that in your query. You may find that
the w numbers returned by DATEPART are a little unusual. You should
probably implement your own ws rather than rely on Micrososft's
definition. That's my experience with most company calendars anyway.
David Portas
SQL Server MVP
--|||The Microsoft DatePart, was what type of calendar ws we where looking for
.
How would I go about creating a Calendar Table? I would feel safer if i
could write a calendar query/function/procedure, something that does not hav
e
to be updated.
Thanks for info!
Ken
"David Portas" wrote:

> Create a Calendar table and join that in your query. You may find that
> the w numbers returned by DATEPART are a little unusual. You should
> probably implement your own ws rather than rely on Micrososft's
> definition. That's my experience with most company calendars anyway.
> --
> David Portas
> SQL Server MVP
> --
>|||http://www.aspfaq.com/show.asp?id=2519
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Ken" <Ken@.discussions.microsoft.com> wrote in message
news:45691A05-1E7A-4621-B202-839D9DCEE7BE@.microsoft.com...
> The Microsoft DatePart, was what type of calendar ws we where looking f
or.
> How would I go about creating a Calendar Table? I would feel safer if i
> could write a calendar query/function/procedure, something that does not h
ave
> to be updated.
> Thanks for info!
> Ken
> "David Portas" wrote:
>

No comments:

Post a Comment