Upload
vladomanija
View
27
Download
6
Embed Size (px)
Citation preview
Beginning with Delphi 6, Delphi’s runtime library (RTL)was expanded with a number of new units. One of these,DateUtils.pas, contains more than 150date/time-related routines and associated constants. If yourapplications ever need to work with datesTDateTime values, this unit deserves your close inspection.
Here are just of few of the interesting routines that you canfind in this unit:
CompareDate Requires two TDateTime values. Returnswhether the first date is prior to, is equal to, or islater than the second date.
DaysInMonth Pass a TDateTime value. Returns thenumber of days in the month associated with thepassed date.
DayOfTheMonth Pass a TDateTime parameter. Returnsthe number of days represented by this TDateTimesince the last day of the preceding month.
DaySpan Pass two TDateTime values. Returns thenumber of days between the two dates.
DecodeDayMonthWeek Pass a TDateTime parameterand four Word out parameters. The TDateTime isdecoded, and the four Word parameters are assignedthe year number, month number, week into the year,and day of the week, respectively.
EndOfAMonth Pass in a year number and a monthnumber, both as Word values. Returns a TDateTimevalue for the last day of the specified month.
EndOfAYear Pass a year number as a Word. Returns aTDateTime value for the last day of that year.
HourOfTheYear Pass a TDateTime value. Returns thenumber of hours into the year represented by thatTDateTime.
IncDay Pass in a TDateTime and some number of days.Returns a TDateTime specified number of days inthe future.
IncMinutes Same as IncDay, but returns a TDateTimethe specified number of minutes in the future.
IsInLeapYear Pass a TDateTime. Returns a Booleanvalue indicating whether or not the year in which theTDateTime resides in a leap year.
IsValidDate Pass a year number, month number, and daynumber. Returns a Boolean value indicating whetherthe numbers constitute a real date.
IsToday Pass in a TDateTime. Returns a Boolean valueindicating whether or not that TDateTime representsthe same date as the current date.
MinuteOfTheDay Pass a TDateTime parameter. Returnsthe number of minutes since midnight that thisTDateTime represents.
SameDate Pass in two TDateTime parameters. Returnsa Boolean value indicating whether or not those twoTDateTimes represent the same date.
StartOfAMonth Pass in a year and month number.Returns a TDateTime value that points to the firstday of that month.
StartOfAWeek Similar to StartOfAMonth, returns thefirst day of the week associated with the given date.This function is ISO 8601 compliant. More aboutthis is said later in his section.
WithinPastHours Pass two TDateTime values andsome number of hours. Returns a Boolean valueindicating if the two TDateTimes represent valueswithin the specified number of hours.
YearOf Pass in a TDateTime. Returns the year numberof the specified date.
This is just a small sampling of the routines that you willfind in the DateUtils unit. In addition, nearly every categoryof function has its equivalents for eachtime metric. For example, the following functions appearin the DateUtils unit: YearOf, MonthOf, WeekOf, DayOf,HourOf, MinuteOf, SecondOf, and MilliSecondOf.
Many of the functions in the DateUtils unit are ISO 8601compliant. As documented with comments at the beginningof the DateUtils unit, ISO 8601 specifies whatconstitutes the first week of the year, the first day of a month,and so on. ISO 8601compliant functions are flagged usingcomments in the interface section of the DateUtils unit.Foradditional 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 DateUtilsunit where contributed by Delphi developers, includingJeroen 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 inwhich you installed Delphi 6 or later.
Did You Know? Delphi’s Date/
Time Functions
by Cary JensenThis information and much more is available on Cary’s bi-monthly, free Developer Days ELetter, to which you can signup on http://www.DeveloperDays.com .