Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Difference between weeks

Former Member
0 Likes
1,857

Hi All,

I have used DATE_GET_WEEK function to determine week for different dates. Now I have to find the difference between the weeks. If the years are same the simple subtraction works, but for example difference bwetween 200953 and 201008 does not give me the desired answer.

If I do 201008 - 201001 it gives a good number as 7.

But if I do 201008 - 200950 it gies 8. It should have been a different number.

Any idea how to subtract two weeks?

Thanks,

Arthur.

1 ACCEPTED SOLUTION
Read only

jrg_wulf
Active Contributor
0 Likes
1,290

Hi Alex,

i don't see, why you don't just subtract your original dates, thus receiving the number of days between them and divide by 7.

To get only complete weeks, just div them. With a bit of day of week fiddling on one of your dates, you can even determine calendar weeks.

hope it helps.

regards

Jörg

8 REPLIES 8
Read only

Former Member
0 Likes
1,290

201008 - 200950 give 58 not 8.

Rob

Read only

0 Likes
1,290

Rob,

When you subtract two variables(SCAL-WEEK) with values 201008 - 200950, you get 8, not 58. But in the calculator artithmatic it is 58. But still it is wrong. I am looking for the difference between two weeks. 2009 has 53 weeks. so 3 weeks from 2009 and 8 weeks from 2010, so the difference should have been 11.

Hope this clears it.

Thank you.

Arthur.

Edited by: Alex Arthur Samson on Feb 24, 2010 12:16 PM

Read only

0 Likes
1,290

And the answer you want is 10 - correct?

Rob

Read only

jrg_wulf
Active Contributor
0 Likes
1,291

Hi Alex,

i don't see, why you don't just subtract your original dates, thus receiving the number of days between them and divide by 7.

To get only complete weeks, just div them. With a bit of day of week fiddling on one of your dates, you can even determine calendar weeks.

hope it helps.

regards

Jörg

Read only

Former Member
0 Likes
1,290

Rob,

yes you are correct.

Jorg,

Dividing by no of days is a good strategy, but I am not sure about the weeks as the beginning of each year could be different in each organization, so the start of week 1 does not necessarily mean calweek 1. So if I have no other options I may do that, but I will try in my case and see what I get.

Thank you for the suggestion.

Arthur.

Read only

Former Member
0 Likes
1,290

You determine the difference in the number of years. In this case it is 1. You multiply that by 52. add that to the number of weeks in the "to" field. Her it would be 52 + 8 = 60. Then subtract the "from" weeks. So 60 - 50 = 10.

Rob

Read only

Former Member
0 Likes
1,290

Rob,

I overlooked the result declaration as RESULT TYPE N. Since the result was in 2 digits it was not showing it. The change in code fixed it.

Thanks,

Arthur.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,290

Check this link:[http://sapprograms.blogspot.com/2008/11/to-calculate-week-difference-between.html]