RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
DateUtils.WeekOfTheMonth Function

Returns the week of the month represented by a TDateTime value.

Pascal
function WeekOfTheMonth(const AValue: TDateTime): Word; overload;
function WeekOfTheMonth(const AValue: TDateTime; var AYear: Word; var AMonth: Word): Word; overload;
C++
Word WeekOfTheMonth(const TDateTime AValue);
Word WeekOfTheMonth(const TDateTime AValue, Word AYear, Word AMonth);

DateUtils

Call WeekOfTheMonth to obtain the week of the month represented by a specified TDateTime value. WeekOfTheMonth returns a value between 1 and 6. 

AYear and AMonth return the year and month in which WeekOfTheMonth occurs. Note that these values may not be the same as the year and month of AValue. This is because the first week of a month is defined as the first week with four or more days in that month. Thus, if the first day of the month is a Friday, Saturday, or Sunday, the first one, two, or three days of the month are defined as belonging to the last week of the previous month. Similarly, if the last day of the month is a Monday, Tuesday, or Wednesday, then the last one, two, or three days of the month are defined as belonging to the first week of the next month.

Tip: To count weeks based on the weekday of the date/time value, use the NthDayOfWeek function instead. For example, if AValue represents a Saturday that is the first day of a month, WeekOfTheMonth returns 5 (or maybe 4), indicating the last week of the previous month, while NthDayOfWeek returns 1 AValue is the first Saturday in the month.
Note: WeekOfTheMonth uses the ISO 8601 standard definition of a week. That is, a week is considered to start on a Monday and end on a Sunday.
 

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!