‎2010 Feb 24 5:02 PM
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.
‎2010 Feb 24 6:08 PM
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
‎2010 Feb 24 5:14 PM
‎2010 Feb 24 5:15 PM
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
‎2010 Feb 24 5:24 PM
‎2010 Feb 24 6:08 PM
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
‎2010 Feb 24 6:26 PM
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.
‎2010 Feb 24 6:51 PM
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
‎2010 Feb 24 7:29 PM
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.
‎2010 Feb 24 7:32 PM
Check this link:[http://sapprograms.blogspot.com/2008/11/to-calculate-week-difference-between.html]