× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



What are you looking for? the number of days, or the number of weeks?

Essentially,

nbrDays = %diff(date2: date1: *days)
nbrWeeks = (%diff(date2: date1: *days)) / 7

// if the remainder is more than 3 days then add a week to the
number of weeks.
if (%rem(%diff(date2: date1: *days)) / 7) >= 4
nbrWeeks = nbrWeeks + 1
endif


Is that the sort of things you are looking for?

If the dividing line must be Saturday to Saturday the algorithm would change slightly. Probably I would:

Get the day-of-week as a number. (Set the number so that Saturday = 0)
Find out what day-of-the-week date1 is, and add the inverse of that number of days to date1, then get the nbrDays / 7 and forget about the remainder.

// Work fields
D wTestDate s d inz(d'2010-04-01')
D wNdx s 10i 0

wNdx = %diff(date1: wTestDate: *days)
wNdx = 7 - (%rem(wNdx: 7))
date1 = date1 + %days(wNdx)
nbrWeeks = (date2 - date1) / 7

(You may have to jiggle the inz(date) back or forward to get Saturday = 0.)

Or something like that, If your two date fields are not real date fields, make them real date fields first. Much easier.

http://www.martinvt.com/Code_Samples/Date_Math/date_math.html Has a few various date math examples.


(I haven't tested this, so it may need some tapping and shoving to get what you want.)






2011/4/7 Tomasz Skorża<t.skorza@xxxxxxxxxxx>:
Hi

I need to create an algorithm which allow me to calculate diffrence between two dates but assumption
is that first day of week is SATURDAY, and week going from saturday to friday.
So if first date is 2011-03-28 - monday, then for second date from 2011-03-29 to 2011-04-01
algorithm should return 1 (week), but for 2011-04-02 - saturday algorithm should return 2 (weeks).
Have you any idea?

I tried many posssibilities and something is wrong, depend on start and stop dates sometimes result
is as I expect sometimes not ...

Regards

Tomek
--



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.