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


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

Re: Working with dates in VB6

From Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid>
Newsgroups comp.lang.basic.visual.misc
Subject Re: Working with dates in VB6
Date 2013-02-25 17:10 +0000
Organization Home
Message-ID <7ZD49OEVs5KRFw41@invalid.uk.co.demon.merlyn.invalid> (permalink)
References <VA.000042f2.54f56eb7@ukrm.net>

Show all headers | View raw


In comp.lang.basic.visual.misc message <VA.000042f2.54f56eb7@ukrm.net>,
Sun, 24 Feb 2013 19:56:28, R C Nesbit <spam@ukrm.net> posted:

>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?

You only need Weekday to get the day-of-week of the first day; ISO 8601
week numbers follow a simple 1-7 1-7 sequence, rolling over on Sunday
night.

While there are more than 6 days left, you can just add 7 to the day
count and 5 to the work-day count.

Better still, use integer division of the date difference to get the
number of 7-day units, ..., and short-circuit the previous paragraph.

But is hire charged for Official Holidays, such as Good Friday, Easter
Monday, etc.?

-- 
 (c) John Stockton, nr London, UK.   E-mail, see Home Page.    Turnpike v6.05.
 Website  <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
 PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
 Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

Back to comp.lang.basic.visual.misc | Previous | NextPrevious 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