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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to calculate number of weeks between current date and a receipt date 1

Status
Not open for further replies.

staceyn

Technical User
Nov 19, 2004
107
US
Hello,
I am using business intelligence development studio 2008 and am trying to figure out how to do a calculation that will return the number of weeks an item has been in stock. The calculation should be determining the number of weeks between the receipt date of an item and the current date. How would I go about creating this calculation?

Thanks,
Stacey
 
You should be able to use DateDiff:

Code:
=DateDiff("WEEK",Fields!ReceiptDate.Value,Today())

-- Francis
Francisus ego, sed non sum papa.
 
You can do it in tour dataset query

Declare @ReceiptDate Varchar(10)

Set @ReceiptDate = '2001-01-01'

Select DATEDIFF(WEEK, @ReceiptDate, Cast(GetDate() AS DATE)) DateInStock
 

Both of the above answers will give you the number of weekends the item has been in stock not the number of weeks.

Datediff does not calculate the number of periods between 2 dates it gives you the number of period ends.

Example if you use DATEDIFF(YEAR, '2013-12-31', '2014-01-01') it returns 1 because you passed the period end (new years eve) same applies to months, weeks etc.

If you wan the number of complete weeks in stock properly you need to calculate in days then divide by 7 and round down.



I love deadlines. I like the whooshing sound they make as they fly by
Douglas Adams
(1952-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top