Scalabium Software |
|
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: dt := EncodeDate(2001, 11, 1); 2. to calculate a first Wednesday in the November: while (DayOfWeek(dt) <> 4) do 3. to calculate a next Wednesday: dt := dt + 7; The similar method you can use for calculation of last
Wednesday of November 2001: dt := EncodeDate(2001, 11, 30); 2. to calculate a last Wednesday in the November: while (DayOfWeek(dt) <> 4) do 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.
|
Copyright© 1998-2024, Scalabium
Software. All rights reserved. |