Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #1719

Working with dates in VB6

From R C Nesbit <spam@ukrm.net>
Newsgroups comp.lang.basic.visual.misc
Subject Working with dates in VB6
Date 2013-02-24 19:56 +0000
Organization SpamTrap
Message-ID <VA.000042f2.54f56eb7@ukrm.net> (permalink)

Show all headers | View raw


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


Back to comp.lang.basic.visual.misc | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Working with dates in VB6 R C Nesbit <spam@ukrm.net> - 2013-02-24 19:56 +0000
  Re: Working with dates in VB6 Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-02-25 17:10 +0000

csiph-web