Path: csiph.com!usenet.pasdenom.info!aioe.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: R C Nesbit Newsgroups: comp.lang.basic.visual.misc Subject: Working with dates in VB6 Date: Sun, 24 Feb 2013 19:56:28 -0000 Organization: SpamTrap Lines: 45 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: individual.net T0KBJOuRoOS6YgfEsBH+0gXVJrxqpQRUN1loLOtLF16dTgfDb5qq8ef5KrKUDEs13s Cancel-Lock: sha1:JUFPfJKR0nDntDZm9U9ce4c9x28= X-Newsreader: Virtual Access Open Source http://www.virtual-access.org/ Xref: csiph.com comp.lang.basic.visual.misc:1719 Problem: Plant hire - the plant is hired by the day, but the hire charge is by the week. The hire charge is actually levied by the day, but only Monday to Friday, i.e. if it is 100/week the charge is 20/day Records hold an item of plant, the weekly rate, the date on hire, and the date off-hire The application looks at the record and the default date off-hire is 1 day *before* the date on hire, unless the hire is ended, when the off-hire date is set. So the app must calculate the cost so far, or the cost from on-hire to off-hire if the off-hire is changed to a data after the on-hire date. Problem is working out the cost for the on-hire days, only accounting for Mon to Fri over days or weeks. My solution is a function CalcHireCost, passed paramaters on-hire(FDate), off-hire(TDate), and Rate then I have: iDays = DateDiff("d", FDate, TDate, vbMonday) iSDay = 0 For i = 1 To iDays If Weekday(DateAdd("d", i, FDate), vbMonday) < 6 Then iSDay = iSDay + 1 End If Next i CalcHireCost = (iSDay * (Rate / 5)) Can anyone improve on this or see any logic-bombs in it? -- Rob Pearson