Sign in Join
FPDoc Onlineexperiment

DateUtils unit

Date/Time manipulation routines.

DateUtils contains a large number of date/time manipulation routines, all based on the TDateTime type. There are routines for date/time math, for comparing dates and times, for composing dates and decomposing dates in their constituent parts.

Classes and records

EDateTimeExceptionclass
ELocalTimeInvalidclass
TDateTimeHelperhelper
TTimeZoneclass

Procedures and functions

CompareDatefunctionCompare 2 dates, disregarding the time of day.
CompareDateTimefunctionCompare 2 dates, taking into account the time of day.
CompareTimefunctionCompares two times of the day, disregarding the date part.
DateInRangefunctionChecks whether a date value is in a given rang.
DateOffunctionExtract the date part from a TDateTime indication.
DateTimeInRangefunctionChecks whether a date/time value is in a given range.
DateTimeToDosDateTimefunctionConvert TDateTime format to DOS date/time format.
DateTimeToJulianDatefunctionConverts a TDateTime value to a Julian date representation.
DateTimeToMacfunctionConvert a TDateTime timestamp to a Mac timestamp.
DateTimeToModifiedJulianDatefunctionConvert a TDateTime value to a modified Julian date representation.
DateTimeToUnixfunctionConvert a TDateTime value to Unix epoch time.
DateToISO8601functionConverts a TDateTime value to ISO 8601 date/time format.
DayOffunctionExtract the day (of month) part from a TDateTime value.
DayOfTheMonthfunctionExtract the day (of month) part of a TDateTime value.
DayOfTheWeekfunctionExtracts the day of the week from a TDateTime value.
DayOfTheYearfunctionExtracts the day of the year from a TDateTime value.
DaysBetweenfunctionNumber of whole days between two TDateTime values.
DaysInAMonthfunctionNumber of days in a month of a certain year.
DaysInAYearfunctionNumber of days in a particular year.
DaysInMonthfunctionReturn the number of days in the month in which a date occurs.
DaysInYearfunctionReturn the number of days in the year in which a date occurs.
DaySpanfunctionCalculate the approximate number of days between two TDateTime values.
DecodeDateDayprocedureDecode a TDateTime value in year and year of day.
DecodeDateMonthWeekprocedureDecode a TDateTime value in a month, week of month and day of week.
DecodeDateTimeprocedureDecode a TDateTime value in a date and time value.
DecodeDateWeekprocedureDecode a TDateTime value in a week of year and day of week.
DecodeDayOfWeekInMonthprocedureDecode a TDateTime value in year, month, day of week parts.
DosDateTimeToDateTimefunctionConvert DOS date/time format to TDateTime format.
EncodeDateDayfunctionEncodes a year and day of year to a TDateTime value.
EncodeDateMonthWeekfunctionEncodes a year, month, week of month and day of week to a TDateTime value.
EncodeDateTimefunctionEncodes a TDateTime value from all its parts.
EncodeDateWeekfunctionEncode a TDateTime value from a year, week and day of week triplet.
EncodeDayOfWeekInMonthfunctionEncodes a year, month, week, day of week specification to a TDateTime value.
EncodeTimeIntervalfunctionEncode an interval as a TDateTime value.
EndOfADayfunctionCalculates a TDateTime value representing the end of a specified day.
EndOfAMonthfunctionCalculate a TDateTime value representing the last day of the indicated month.
EndOfAWeekfunctionReturn the last moment of day of the week, given a year and a week in the year.
EndOfAYearfunctionCalculate a TDateTime value representing the last day of a year.
EndOfTheDayfunctionCalculate a TDateTime value that represents the end of a given day.
EndOfTheMonthfunctionCalculate a TDateTime value representing the last day of the month, given a day in that month.
EndOfTheWeekfunctionCalculate a TDateTime value which represents the end of a week, given a date in that week.
EndOfTheYearfunctionCalculate a TDateTime value representing the last day of a year, given a date in that year.
HourOffunctionExtract the hour part from a TDateTime value.
HourOfTheDayfunctionCalculate the hour of a given TDateTime value.
HourOfTheMonthfunctionCalculate the number of hours passed since the start of the month.
HourOfTheWeekfunctionCalculate the number of hours elapsed since the start of the week.
HourOfTheYearfunctionCalculate the number of hours passed since the start of the year.
HoursBetweenfunctionCalculate the number of whole hours between two TDateTime values.
HourSpanfunctionCalculate the approximate number of hours between two TDateTime values.
IncDayfunctionIncrease a TDateTime value with a number of days.
IncHourfunctionIncrease a TDateTime value with a number of hours.
IncMilliSecondfunctionIncrease a TDateTime value with a number of milliseconds.
IncMinutefunctionIncrease a TDateTime value with a number of minutes.
IncSecondfunctionIncrease a TDateTime value with a number of seconds.
IncWeekfunctionIncrease a TDateTime value with a number of weeks.
IncYearfunctionIncrease a TDateTime value with a number of years.
InvalidDateDayErrorprocedureRaise an EConvertError exception when a day is not a valid day of a year.
InvalidDateMonthWeekErrorprocedureRaise an EConvertError exception when a Year,Month,WeekOfMonth,DayofWeek is invalid.
InvalidDateTimeErrorprocedureRaise an EConvertError about an invalid date-time specification.
InvalidDateWeekErrorprocedureRaise an EConvertError with an invalid Year, WeekOfyear and DayOfWeek specification.
InvalidDayOfWeekInMonthErrorprocedureRaise an EConvertError exception when a Year,Month,NthDayofWeek,DayofWeek is invalid.
IsAMfunction
IsInLeapYearfunctionDetermine whether a date is in a leap year.
ISO8601ToDatefunctionConverts a date/time value in ISO 8601 notation to a native TDateTime type.
ISO8601ToDateDeffunctionConverts an ISO 8601 date/time string to a TDateTime type.
IsPMfunctionDetermine whether a time is PM or AM.
IsSameDayfunctionCheck if two date/time indications are the same day.
IsSameMonthfunctionCheck if 2 dates are in the same month.
IsTodayfunctionCheck whether a given date is today.
IsValidDatefunctionCheck whether a set of values is a valid date indication.
IsValidDateDayfunctionCheck whether a given year/day of year combination is a valid date.
IsValidDateMonthWeekfunctionCheck whether a given year/month/week/day of the week combination is a valid day.
IsValidDateTimefunctionCheck whether a set of values is a valid date and time indication.
IsValidDateWeekfunctionCheck whether a given year/week/day of the week combination is a valid day.
IsValidTimefunctionCheck whether a set of values is a valid time indication.
JulianDateToDateTimefunctionConvert a Julian date representation to a TDateTime value.
LocalTimeToUniversalfunctionConvert local time to UTC time.
MacTimeStampToUnixfunctionConvert a Mac timestamp to a Unix timestamp.
MacToDateTimefunctionConvert a Mac timestamp to a TDateTime timestamp.
MilliSecondOffunctionExtract the millisecond part from a TDateTime value.
MilliSecondOfTheDayfunctionCalculate the number of milliseconds elapsed since the start of the day.
MilliSecondOfTheHourfunctionCalculate the number of milliseconds elapsed since the start of the hour.
MilliSecondOfTheMinutefunctionCalculate the number of milliseconds elapsed since the start of the minute.
MilliSecondOfTheMonthfunctionCalculate number of milliseconds elapsed since the start of the month.
MilliSecondOfTheSecondfunctionCalculate the number of milliseconds elapsed since the start of the second.
MilliSecondOfTheWeekfunctionCalculate the number of milliseconds elapsed since the start of the week.
MilliSecondOfTheYearfunctionCalculate the number of milliseconds elapsed since the start of the year.
MilliSecondsBetweenfunctionCalculate the number of whole milliseconds between two TDateTime values.
MilliSecondSpanfunctionCalculate the approximate number of milliseconds between two TDateTime values.
MinuteOffunctionExtract the minute part from a TDateTime value.
MinuteOfTheDayfunctionCalculate the number of minutes elapsed since the start of the day.
MinuteOfTheHourfunctionCalculate the number of minutes elapsed since the start of the hour.
MinuteOfTheMonthfunctionCalculate number of minutes elapsed since the start of the month.
MinuteOfTheWeekfunctionCalculate the number of minutes elapsed since the start of the week.
MinuteOfTheYearfunctionCalculate the number of minutes elapsed since the start of the year.
MinutesBetweenfunctionCalculate the number of whole minutes between two TDateTime values.
MinuteSpanfunctionCalculate the approximate number of minutes between two TDateTime values.
ModifiedJulianDateToDateTimefunctionConvert a modified Julian date representation to a TDateTime value.
MonthOffunctionExtract the month from a given date.
MonthOfTheYearfunctionExtract the month of a TDateTime indication.
MonthsBetweenfunctionCalculate the number of whole months between two TDateTime values.
MonthSpanfunctionCalculate the approximate number of months between two TDateTime values.
NthDayOfWeekfunctionCalculate which occurrence of weekday in the month a given day represents.
PeriodBetweenprocedureReturn the period (in years, months, days) between two dates.
PreviousDayOfWeekfunctionGiven a day of the week, return the previous day of the week.
RecodeDatefunctionReplace date part of a TDateTime value with another date.
RecodeDateTimefunctionReplace selected parts of a TDateTime value with other values.
RecodeDayfunctionReplace day part of a TDateTime value with another day.
RecodeHourfunctionReplace hours part of a TDateTime value with another hour.
RecodeMilliSecondfunctionReplace milliseconds part of a TDateTime value with another millisecond.
RecodeMinutefunctionReplace minutes part of a TDateTime value with another minute.
RecodeMonthfunctionReplace month part of a TDateTime value with another month.
RecodeSecondfunctionReplace seconds part of a TDateTime value with another second.
RecodeTimefunctionReplace time part of a TDateTime value with another time.
RecodeYearfunctionReplace year part of a TDateTime value with another year.
SameDatefunctionCheck whether two TDateTime values have the same date part.
SameDateTimefunctionCheck whether two TDateTime values have the same date and time parts.
SameTimefunctionCheck whether two TDateTime values have the same time part.
ScanDateTimefunctionScans a string for a TDateTime pattern and returns the date/time.
SecondOffunctionExtract the second part from a TDateTime value.
SecondOfTheDayfunctionCalculate the number of seconds elapsed since the start of the day.
SecondOfTheHourfunctionCalculate the number of seconds elapsed since the start of the hour.
SecondOfTheMinutefunctionCalculate the number of seconds elapsed since the start of the minute.
SecondOfTheMonthfunctionCalculate number of seconds elapsed since the start of the month.
SecondOfTheWeekfunctionCalculate the number of seconds elapsed since the start of the week.
SecondOfTheYearfunctionCalculate the number of seconds elapsed since the start of the year.
SecondsBetweenfunctionCalculate the number of whole seconds between two TDateTime values.
SecondSpanfunctionCalculate the approximate number of seconds between two TDateTime values.
StartOfADayfunctionReturns the start of a day as a TDateTime value, given a day indication.
StartOfAMonthfunctionReturn first date of month, given a year/month pair.
StartOfAWeekfunctionReturn a day of the week, given a year, week and day in the week.
StartOfAYearfunctionReturn the first day of a given year.
StartOfTheDayfunctionCalculate the start of the day as a TDateTime value, given a moment in the day.
StartOfTheMonthfunctionCalculate the first day of the month, given a date in that month.
StartOfTheWeekfunctionReturn the first day of the week, given a date.
StartOfTheYearfunctionReturn the first day of the year, given a date in this year.
TimeInRangefunctionChecks whether a time value is in a given range.
TimeOffunctionExtract the time part from a TDateTime indication.
TodayfunctionReturn the current date.
TomorrowfunctionReturn the next day after today.
TryEncodeDateDayfunctionEncode a year and day of year to a TDateTime value.
TryEncodeDateMonthWeekfunctionEncode a year, month, week of month and day of week to a TDateTime value.
TryEncodeDateTimefunctionEncode a Year, Month, Day, Hour, minute, seconds, milliseconds tuplet to a TDateTime value.
TryEncodeDateWeekfunctionEncode a year, week and day of week triplet to a TDateTime value.
TryEncodeDayOfWeekInMonthfunctionEncode a year, month, week, day of week triplet to a TDateTime value.
TryEncodeTimeIntervalfunctionTry to encode an interval as a TDateTime value.
TryISO8601ToDatefunctionAttempts to convert an ISO 8601-formatted date/time value to a TDateTime type.
TryISOStrToDatefunctionAttempts to convert an ISO 8601-formatted date value to a TDateTime type.
TryISOStrToDateTimefunctionAttempts to convert an ISO 8601-formatted date/time value to a TDateTime type.
TryISOStrToTimefunctionConverts an ISO 8601-formatted time value to a TDateTime type.
TryISOTZStrToTZOffsetfunctionAttempts to convert an ISO 8601 time zone designation to an offset in minutes.
TryJulianDateToDateTimefunctionConvert a Julian date representation to a TDateTime value.
TryModifiedJulianDateToDateTimefunctionConvert a modified Julian date representation to a TDateTime value.
TryRecodeDateTimefunctionReplace selected parts of a TDateTime value with other values.
UniversalTimeToLocalfunctionConvert UTC time to local time.
UnixTimeStampToMacfunctionConvert Unix Timestamp to a Mac Timestamp.
UnixToDateTimefunctionConvert Unix epoch time to a TDateTime value.
WeekOffunctionExtract week (of the year) from a given date.
WeekOfTheMonthfunctionExtract the week of the month (and optionally month and year) from a TDateTime value.
WeekOfTheYearfunctionExtract the week of the year (and optionally year) of a TDateTime indication.
WeeksBetweenfunctionCalculate the number of whole weeks between two TDateTime values.
WeeksInAYearfunctionReturns the number of weeks in a given year.
WeeksInYearfunctionReturns the number of weeks in the year, given a date.
WeekSpanfunctionCalculate the approximate number of weeks between two TDateTime values.
WithinPastDaysfunctionCheck whether two TDateTimes are only a number of days apart.
WithinPastHoursfunctionCheck whether two TDateTimes are only a number of hours apart.
WithinPastMilliSecondsfunctionCheck whether two TDateTimes are only a number of milliseconds apart.
WithinPastMinutesfunctionCheck whether two TDateTimes are only a number of minutes apart.
WithinPastMonthsfunctionCheck whether two TDateTimes are only a number of months apart.
WithinPastSecondsfunctionCheck whether two TDateTimes are only a number of seconds apart.
WithinPastWeeksfunctionCheck whether two TDateTimes are only a number of weeks apart.
WithinPastYearsfunctionCheck whether two TDateTimes are only a number of years apart.
YearOffunctionExtract the year from a given date.
YearsBetweenfunctionCalculate the number of whole years between two TDateTime values.
YearSpanfunctionCalculate the approximate number of years between two TDateTime values.
YesterdayfunctionReturn the previous day.

Types

TLocalTimeTypeenumeration

Constants

ApproxDaysPerMonthconstantAverage number of days in a month, measured over a year. Used in .
ApproxDaysPerYearconstantAverage number of days in a year, measured over 4 years. Used in .
DateTimeEpsilonconstant
DayFridayconstantISO day number for Friday.
DayMondayconstantISO day number for Monday.
DaySaturdayconstantISO day number for Saturday.
DaysPerWeekconstantNumber of days in a week.
DaysPerYearconstantArray with number of days in a year. The Boolean index indicates whether it is a leap year or not.
DaySundayconstantISO day number for Sunday.
DayThursdayconstantISO day number for Thursday.
DayTuesdayconstantISO day number for Tuesday.
DayWednesdayconstantISO day number for Wednesday.
MonthAprilconstantISO month number for April.
MonthAugustconstantISO month number for August.
MonthDecemberconstantISO month number for December.
MonthFebruaryconstantISO month number for february.
MonthJanuaryconstantISO month number for january.
MonthJulyconstantISO month number for July.
MonthJuneconstantISO month number for June.
MonthMarchconstantISO month number for March.
MonthMayconstantISO month number for May.
MonthNovemberconstantISO month number for November.
MonthOctoberconstantISO month number for October.
MonthSeptemberconstantISO month number for September.
MonthsPerYearconstantNumber of months in a year.
OneHourconstantOne hour as a fraction of a day (suitable for TDateTime).
OneMillisecondconstantOne millisecond as a fraction of a day (suitable for TDateTime).
OneMinuteconstantOne minute as a fraction of a day (suitable for TDateTime).
OneSecondconstantOne second as a fraction of a day (suitable for TDateTime).
RecodeLeaveFieldAsIsconstantBitmask deciding what to do with each TDateTime field in recode routines.
WeeksPerFortnightconstantNumber of weeks in fortnight.
YearsPerCenturyconstantNumber of years in a century.
YearsPerDecadeconstantNumber of years in a decade.
YearsPerMillenniumconstantNumber of years in a millennium.

Uses

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.