Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to calc number of weeks between two dates?
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00658482
Message ID:
00658486
Views:
23
>>Maybe because it's Friday afternoon, but I can't seem to figure out this problem. Any help would be greatly appreciated.
>>
>>I am working on a Human Resources project, that in part, has to determine some benefit accruals based on years of service, etc. etc. (Why do Union guys have better benefits than I do anyway? Oh well, that's a different topic better discussed over a couple of beers!)
>>
>>One accrual is dependent on the number of weeks that have elapsed. One approach is to write out to a table accruals for every pay period or at month, quarter, or year end close.
>>
>>But I think it would be better to calc the accruals on the fly and without having to create and maintain yet another table. And this brings us to the place where I need help.
>>
>>Does anyone know a method for calculating the number of weeks that have elapsed between two dates? If only 3 days of a begining or ending date are in the date range, then that week is not counted. If 4 or more days are in a beginning or ending week, then the week is counted in the total.
>>
>>Again, any insight, comments or LOL remarks would be appreciated.
>>
>>Thanks
>>Don Lowrey
? fWeeksService( {^1998/05/17}, Date() )
>
>***************************************
>Function fWeeksService( dStart, dStop )
>***************************************
>   If Not ( Type( "dStart" ) == "D" And Type( "dStop" ) == "D" ) ;
>      Or Empty( dStart ) Or Empty( dStop ) ;
>      Or IsNull( dStart ) Or IsNull dStop ) Then
>      Error "Invalid parameters passed to fWeeksService()."
>   Endif
>   dStart = {^1998/05/17}
>   dToday = Date()
>   iRemainder = Mod( dToday - dStart, 7 )
>   iWeeksService = Int( ( dToday - dStart ) / 7 )
>   If iRemainder > 3 Then
>      iWeeksService = iWeeksService + 1
>   Endif
>   Return iWeeksService
>   EndFunc  && fWeeksService( dStart, dStop ).
Make dToday dStop
censored.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform