On Feb 15, 2006, at 3:54 AM, Emile Schwarz wrote:
Hi all,
this is a simple problem to resolve:
how many days between two dates ?
how many weeks between two dates ?
Here is the approach - and code - I used:
I take the start and end dates from two EditFields with ##-##-####
masks (not the best, but they works) and fill DateEnd and DateStart.
// Get the ellapsed time
Delta.TotalSeconds = DateEnd.TotalSeconds - DateStart.TotalSeconds
Dim d As Double
Dim numWeeks As Double
d = DateEnd.TotalSeconds - DateStart.TotalSeconds
d = d / (60.0 * 60.0 * 24.0) // 60 sec/min * 60 min/hr * 24 hr/day
numWeeks = d / 7.0 // 7 day/wk
// Ta daa!
// At this point, if you want the # days excluding sundays, you can get
a rough estimate
by subtracting the integral portion of 'numWeeks' from 'd'.
// Compute the number of days and weeks
locWeeks = DateDelta.WeekOfYear - 1 // I do not know why - 1 ...
locDays = locWeeks * 6 // Skip Sundays
// Report the computed values in two EditFields
EFResultDays.Text = Str(locDays)
EFResultWeeks.Text = Str(locWeeks)
The above code works fine if the dates are within the same year _AND
ARE NOT SUNDAY DATES_, but do not works for different years - for
example: 30-10-1937 to 29-05-1938 - .
What is wrong in my code ?
Emile
Example of sunday dates and results:
Date to compute:
Start date: 30-10-1937
End Date: 20-11-1938
Results:
12 days and 2 weeks which is totally wrong !
Must I make complex math with day, month and years without using my
Delta Date Class ?
Must I use get the TotalSeconds double value and divide it to get the
answer I want ?
I must be tired (Ich been mud ?), lack of sleeping or... but I do not
know where to start again...
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
William H Squires Jr
4400 Horizon Hill #4006
San Antonio, TX 78229
[EMAIL PROTECTED] <- remove the .nospam
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>