You are on page 1of 1

Beginning with Delphi 6, Delphis runtime library (RTL)

was expanded with a number of new units. One of these,


DateUtils.pas, contains more than 150
date/time-related routines and associated constants. If your
applications ever need to work with dates
TDateTime values, this unit deserves your close inspection.
Here are just of few of the interesting routines that you can
find in this unit:
CompareDate Requires two TDateTime values. Returns
whether the first date is prior to, is equal to, or is
later than the second date.
DaysInMonth Pass a TDateTime value. Returns the
number of days in the month associated with the
passed date.
DayOfTheMonth Pass a TDateTime parameter. Returns
the number of days represented by this TDateTime
since the last day of the preceding month.
DaySpan Pass two TDateTime values. Returns the
number of days between the two dates.
DecodeDayMonthWeek Pass a TDateTime parameter
and four Word out parameters. The TDateTime is
decoded, and the four Word parameters are assigned
the year number, month number, week into the year,
and day of the week, respectively.
EndOfAMonth Pass in a year number and a month
number, both as Word values. Returns a TDateTime
value for the last day of the specified month.
EndOfAYear Pass a year number as a Word. Returns a
TDateTime value for the last day of that year.
HourOfTheYear Pass a TDateTime value. Returns the
number of hours into the year represented by that
TDateTime.
IncDay Pass in a TDateTime and some number of days.
Returns a TDateTime specified number of days in
the future.
IncMinutes Same as IncDay, but returns a TDateTime
the specified number of minutes in the future.
IsInLeapYear Pass a TDateTime. Returns a Boolean
value indicating whether or not the year in which the
TDateTime resides in a leap year.
IsValidDate Pass a year number, month number, and day
number. Returns a Boolean value indicating whether
the numbers constitute a real date.
IsToday Pass in a TDateTime. Returns a Boolean value
indicating whether or not that TDateTime represents
the same date as the current date.
MinuteOfTheDay Pass a TDateTime parameter. Returns
the number of minutes since midnight that this
TDateTime represents.
SameDate Pass in two TDateTime parameters. Returns
a Boolean value indicating whether or not those two
TDateTimes represent the same date.
StartOfAMonth Pass in a year and month number.
Returns a TDateTime value that points to the first
day of that month.
StartOfAWeek Similar to StartOfAMonth, returns the
first day of the week associated with the given date.
This function is ISO 8601 compliant. More about
this is said later in his section.
WithinPastHours Pass two TDateTime values and
some number of hours. Returns a Boolean value
indicating if the two TDateTimes represent values
within the specified number of hours.
YearOf Pass in a TDateTime. Returns the year number
of the specified date.
This is just a small sampling of the routines that you will
find in the DateUtils unit. In addition, nearly every category
of function has its equivalents for each
time metric. For example, the following functions appear
in the DateUtils unit: YearOf, MonthOf, WeekOf, DayOf,
HourOf, MinuteOf, SecondOf, and MilliSecondOf.
Many of the functions in the DateUtils unit are ISO 8601
compliant. As documented with comments at the beginning
of the DateUtils unit, ISO 8601 specifies what
constitutes the first week of the year, the first day of a month,
and so on. ISO 8601compliant functions are flagged using
comments in the interface section of the DateUtils unit.For
additional information on ISO 8601, see http://www.iso.ch/
iso/en/ISOOnline.frontpage and search for 8601.
Some of the functions and concepts used in the DateUtils
unit where contributed by Delphi developers, including
Jeroen Pluimers, Glenn Crouch, Rune Moberg,
and Ray Lischner. Thanks, guys.
The DateUtils.pas unit is located in the Source/Rtl/
Common/DateUtils.pas file, located under the directory in
which you installed Delphi 6 or later.
Did You Know? Delphis Date/
Time Functions
by Cary Jensen
This information and much more is available on Carys bi-monthly, free Developer Days ELetter, to which you can sign
up on http://www.DeveloperDays.com .

You might also like