Scalabium Software

SMExport advertising
Knowledge for your independence'.
Home Delphi and C++Builder tips

#125: How can I calculate a date of the "second Wednesday of November"?

Today I want to continue a posting of small routunies for date playing.

In any scheduler you can define the desired time of execution as "Second Wednesday" of some month/year. To calculate such dates is very simple task.

I'll show it on small sample. For example, you want to calculate a date of second Wednesday of November in the 2001.

In this case you must:
1. to receive a date of first day in November 2001:

dt := EncodeDate(2001, 11, 1);

2. to calculate a first Wednesday in the November:

while (DayOfWeek(dt) <> 4) do
dt := dt + 1;

3. to calculate a next Wednesday:

dt := dt + 7;

The similar method you can use for calculation of last Wednesday of November 2001:
1. to receive a date of last day in November 2001:

dt := EncodeDate(2001, 11, 30);

2. to calculate a last Wednesday in the November:

while (DayOfWeek(dt) <> 4) do
dt := dt - 1;

Of course, you can use the similar code for calculation of third Sunday or fourth Friday in any month of any year.

I used this schema in own application for database synchronization which supports a custom scheduler and my users like this feature. I hope that you'll add something like that in the own applications.

Published: September 4, 2001

See also
Clarion Viewer
Paradox to Text converter
dBase Viewer
ExcelFile Viewer
Paradox to MS Access converter
Mail parser (ActiveX)
Clarion to Text converter
Database Information Manager
Excel Reader (dll)
ABA Document Convert

Contact to webmaster


Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2024, Scalabium Software. All rights reserved.

SMExport advertising