473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Week Number In Loop

3
Hi All ,

I am having some problem in week number culculation.

What i have to do is I will get as set of data with ord _week eg.200728,200729,200730

Basically i will have a parameter to control this loop of order week.

let say parameter is 33 so i need to do looping for 33 weeks starting week number exp 200642.

so my week number will expand untill year 2007XX

since we have 52 weeks how actually i can add up the weeks until it reaches 33 weeks for my calculation.

Pls help to guide me.Thanks.
Jul 31 '07 #1
3 2139
ck9663
2,878 Expert 2GB
Hi All ,

I am having some problem in week number culculation.

What i have to do is I will get as set of data with ord _week eg.200728,200729,200730

Basically i will have a parameter to control this loop of order week.

let say parameter is 33 so i need to do looping for 33 weeks starting week number exp 200642.

so my week number will expand untill year 2007XX

since we have 52 weeks how actually i can add up the weeks until it reaches 33 weeks for my calculation.

Pls help to guide me.Thanks.
someone better have a shorter solution than this:


declare @yourdata as int
declare @addthisweek as int

select @yourdata = 200642, @addthisweek = 33

select cast(datepart(year,dateadd(week,@addthisweek,datea dd(week,cast(substring(cast(@yourdata as char(7)),5,3) as smallint),cast('01/01/' + left(cast(@yourdata as char(7)),4) as datetime)))) as varchar(4)) +
cast(datepart(week,dateadd(week,@addthisweek,datea dd(week,cast(substring(cast(@yourdata as char(7)),5,3) as smallint),cast('01/01/' + left(cast(@yourdata as char(7)),4) as datetime)))) as varchar(4))
Jul 31 '07 #2
reesa
3
thank you.


i have tried this bid and its workking.But at the point it suppose to be 200701 it selects it self (weekno) = 200653...but for 200654 it become 200702 which is correct ..i have tried to modify...not much helpful to solve it.
Aug 1 '07 #3
ck9663
2,878 Expert 2GB
thank you.


i have tried this bid and its workking.But at the point it suppose to be 200701 it selects it self (weekno) = 200653...but for 200654 it become 200702 which is correct ..i have tried to modify...not much helpful to solve it.

how about now:

declare @yourdata as int
declare @addthisweek as int



select @yourdata = 200601, @addthisweek = 52

select @yourdata, @addthisweek

select cast(datepart(year,dateadd(week,@addthisweek,datea dd(week,cast(substring(cast(@yourdata as char(7)),5,3) as smallint)-1,cast('01/01/' + left(cast(@yourdata as char(7)),4) as datetime)))) as varchar(4))+
right('00' + cast(datepart(week,dateadd(week,@addthisweek,datea dd(week,cast(substring(cast(@yourdata as char(7)),5,3) as smallint)-1,cast('01/01/' + left(cast(@yourdata as char(7)),4) as datetime)))) as varchar(4)),2),
(dateadd(week,@addthisweek,dateadd(week,cast(subst ring(cast(@yourdata as char(7)),5,3) as smallint)-1,cast('01/01/' + left(cast(@yourdata as char(7)),4) as datetime))))



another thing, if you check datepart(week,'12/31/2006') it will return you 53. the reason is, it's the 53rd week of the year. so you might want to do an if @addthisweek = 53 @addthisweek = @addthisweek - 1 kind of condition...
Aug 1 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
7
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code...
2
by: David Mitchell | last post by:
I have tried using the following code to count the specific number of each weekday but get a compile error "User defined type not defined" which I think relates to the first line of the function: -...
2
by: Rustan | last post by:
Hi Im using GregorianCalendar to find out the current years week numbers. When the user chooses a week number in a dropdown i want to show that week in a table with the corresponding dates. For...
3
by: Mal | last post by:
Hello, Any advice on a function to convert a given week number to a date? Ideally I'd like the first day of that week. I'm using this to compare year to year....using the week number as the...
18
by: Jen | last post by:
Is it possible (how) to display a new record every week (or day) from a recordset?
6
by: aarklon | last post by:
Hi folks, I found an algorithm for calculating the day of the week here:- http://www.faqs.org/faqs/calendars/faq/part1/index.html in the section titled 2.5 what day of the week was 2 august...
3
ADezii
by: ADezii | last post by:
Last Tip, we demonstrated the technique for retrieving data from a DAO Recordset, and placing it into a 2-dimensional Array using the GetRows() Method. This week, we will cover the same exact Method...
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.