472,784 Members | 1,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 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 2090
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.