Various date and time formatting routines accept a format string. to format the date and or time.
The following characters can be used to control the date and time formatting:
-
c
- : shortdateformat + ’ ’ + shorttimeformat
-
d
- : day of month
-
dd
- : day of month (leading zero)
-
ddd
- : day of week (abbreviation)
-
dddd
- : day of week (full)
-
ddddd
- : shortdateformat
-
dddddd
- : longdateformat
-
m
- : month
-
mm
- : month (leading zero)
-
mmm
- : month (abbreviation)
-
mmmm
- : month (full)
-
y
- : year (four digits)
-
yy
- : year (two digits)
-
yyyy
- : year (with century)
-
h
- : hour
-
hh
- : hour (leading zero)
-
n
- : minute
-
nn
- : minute (leading zero)
-
s
- : second
-
ss
- : second (leading zero)
-
t
- : shorttimeformat
-
tt
- : longtimeformat
-
am/pm
- : use 12 hour clock and display am and pm accordingly
-
a/p
- : use 12 hour clock and display a and p accordingly
-
/
- : insert date seperator
-
:
- : insert time seperator
-
”xx”
- : literal text
-
’xx’
- : literal text
-
Declaration:
- TDateTime = Double;
-
Description:
- Many functions return or require a TDateTime type, which contains a date and time in encoded
form. The date and time are converted to a double as follows:
- The date part is stored in the integer part of the double as the number of days passed
since January 1, 1900.
- The time part is stored in the fractional part of the double, as the number of milliseconds
passed since midnight (00:00), divided by the total number of milliseconds in a day.
-
Declaration:
- Function Date: TDateTime;
-
Description:
- Date returns the current date in TDateTime format. For more information about the
TDateTime type, see TDateTime (715).
-
Errors:
- None.
-
See also:
- Time (731),Now (727), TDateTime (715).
Listing: sysutex/ex1.pp
-
Declaration:
- Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
-
Description:
- DateTimeToFileDate function converts a date/time indication in TDateTime format to a
filedate function, such as returned for instance by the FileAge (745) function.
-
Errors:
- None.
-
See also:
- Time (731), Date (715), FileDateToDateTime (724), DateTimeToSystemTime (718),
DateTimeToTimeStamp (719)
Listing: sysutex/ex2.pp
-
Declaration:
- Function DateTimeToStr(DateTime: TDateTime): string;
-
Description:
- DateTimeToStr returns a string representation of DateTime using the formatting specified
in ShortDateTimeFormat. It corresponds to a call to FormatDateTime('c',DateTime) (see
section 22.4, page 714).
-
Errors:
- None.
-
See also:
- FormatDateTime (724), TDateTime (715).
Listing: sysutex/ex3.pp
-
Declaration:
- Procedure DateTimeToString(var Result: string; const FormatStr: string;
const DateTime: TDateTime);
-
Description:
- DateTimeToString returns in Result a string representation of DateTime using the
formatting specified in FormatStr.
for a list of characters that can be used in the FormatStr formatting string, see section 22.4,
page 714.
-
Errors:
- In case a wrong formatting character is found, an EConvertError is raised.
-
See also:
- FormatDateTime (724), section 22.4, page 714.
Listing: sysutex/ex4.pp
-
Declaration:
- Procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime:
TSystemTime);
-
Description:
- DateTimeToSystemTime converts a date/time pair in DateTime, with TDateTime format to
a system time SystemTime.
-
Errors:
- None.
-
See also:
- DateTimeToFileDate (716), SystemTimeToDateTime (730), DateTimeToTimeStamp (719)
Listing: sysutex/ex5.pp
-
Declaration:
- Function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
-
Description:
- DateTimeToSystemTime converts a date/time pair in DateTime, with TDateTime format to
a TTimeStamp format.
-
Errors:
- None.
-
See also:
- DateTimeToFileDate (716), SystemTimeToDateTime (730), DateTimeToSystemTime (718)
Listing: sysutex/ex6.pp
-
Declaration:
- Function DateToStr(Date: TDateTime): string;
-
Description:
- DateToStr converts Date to a string representation. It uses ShortDateFormat as it’s
formatting string. It is hence completely equivalent to a FormatDateTime('ddddd', Date).
-
Errors:
- None.
-
See also:
- TimeToStr (732), DateTimeToStr (717), FormatDateTime (724), StrToDate (728)
Listing: sysutex/ex7.pp
-
Declaration:
- Function DayOfWeek(DateTime: TDateTime): integer;
-
Description:
- DayOfWeek returns the day of the week from DateTime. Sunday is counted as day 1,
Saturday is counted as day 7. The result of DayOfWeek can serve as an index to the
LongDayNames constant array, to retrieve the name of the day.
-
Errors:
- None.
-
See also:
- Date (715), DateToStr (720)
Listing: sysutex/ex8.pp
-
Declaration:
- Procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
-
Description:
- DecodeDate decodes the Year, Month and Day stored in Date, and returns them in the
Year, Month and Day variables.
-
Errors:
- None.
-
See also:
- EncodeDate (722), DecodeTime (721).
Listing: sysutex/ex9.pp
-
Declaration:
- Procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second,
MilliSecond: word);
-
Description:
- DecodeDate decodes the hours, minutes, second and milliseconds stored in Time, and returns
them in the Hour, Minute and Second and MilliSecond variables.
-
Errors:
- None.
-
See also:
- EncodeTime (723), DecodeDate (721).
Listing: sysutex/ex10.pp
-
Declaration:
- Function EncodeDate(Year, Month, Day :word): TDateTime;
-
Description:
- EncodeDate encodes the Year, Month and Day variables to a date in TDateTime format. It
does the opposite of the DecodeDate (721) procedure.
The parameters must lie withing valid ranges (boundaries included):
-
Year
- must be between 1 and 9999.
-
Month
- must be within the range 1-12.
-
Day
- msut be between 1 and 31.
-
Errors:
- In case one of the parameters is out of it’s valid range, 0 is returned.
-
See also:
- EncodeTime (723), DecodeDate (721).
Listing: sysutex/ex11.pp
-
Declaration:
- Function EncodeTime(Hour, Minute, Second, MilliSecond:word): TDateTime;
-
Description:
- EncodeTime encodes the Hour, Minute, Second, MilliSecond variables to a TDateTime
format result. It does the opposite of the DecodeTime (721) procedure.
The parameters must have a valid range (boundaries included):
-
Hour
- must be between 0 and 23.
-
Minute,second
- must both be between 0 and 59.
-
Millisecond
- must be between 0 and 999.
-
Errors:
- In case one of the parameters is outside of it’s valid range, 0 is returned.
-
See also:
- EncodeDate (722), DecodeTime (721).
Listing: sysutex/ex12.pp
-
Declaration:
- Function FileDateToDateTime(Filedate : Longint) : TDateTime;
-
Description:
- FileDateToDateTime converts the date/time encoded in filedate to a TDateTime encoded
form. It can be used to convert date/time values returned by the FileAge (745) or FindFirst
(753)/FindNext (754) functions to TDateTime form.
-
Errors:
- None.
-
See also:
- DateTimeToFileDate (716)
Listing: sysutex/ex13.pp
-
Declaration:
- Function FormatDateTime(FormatStr: string; DateTime: TDateTime):string;
-
Description:
- FormatDateTime formats the date and time encoded in DateTime according to the
formatting given in FormatStr. The complete list of formatting characters can be found in
section 22.4, page 714.
-
Errors:
- On error (such as an invalid character in the formatting string), and EConvertError
exception is raised.
-
See also:
- DateTimeToStr (717), DateToStr (720), TimeToStr (732), StrToDateTime (729)
Listing: sysutex/ex14.pp
-
Declaration:
- Function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer):
TDateTime;
-
Description:
- IncMonth increases the month number in DateTime with NumberOfMonths. It wraps the
result as to get a month between 1 and 12, and updates the year accordingly. NumberOfMonths
can be negative, and can be larger than 12 (in absolute value).
-
Errors:
- None.
-
See also:
- Date (715), Time (731), Now (727)
Listing: sysutex/ex15.pp
-
Declaration:
- Function IsLeapYear(Year: Word): boolean;
-
Description:
- IsLeapYear returns True if Year is a leap year, False otherwise.
-
Errors:
- None.
-
See also:
- IncMonth (725), Date (715)
Listing: sysutex/ex16.pp
-
Declaration:
- Function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
-
Description:
- MSecsTiTimeStamp converts the given number of milliseconds to a TTimeStamp date/time
notation.
Use TTimeStamp variables if you need to keep very precise track of time.
-
Errors:
- None.
-
See also:
- TimeStampToMSecs (732), DateTimeToTimeStamp (719),
Listing: sysutex/ex17.pp
-
Declaration:
- Function Now: TDateTime;
-
Description:
- Now returns the current date and time. It is equivalent to Date+Time.
-
Errors:
- None.
-
See also:
- Date (715), Time (731)
Listing: sysutex/ex18.pp
-
Declaration:
- Function StrToDate(const S: string): TDateTime;
-
Description:
- StrToDate converts the string S to a TDateTime date value. The Date must consist of 1 to
three digits, separated by the DateSeparator character. If two numbers are given, they are
supposed to form the day and month of the current year. If only one number is given, it is
supposed to represent the day of the current month. (This is not supported in Delphi)
The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the ShortDateFormat
variable.
-
Errors:
- On error (e.g. an invalid date or invalid character), an EConvertError exception is raised.
-
See also:
- StrToTime (729), DateToStr (720)n TimeToStr (732).
Listing: sysutex/ex19.pp
-
Declaration:
- Function StrToDateTime(const S: string): TDateTime;
-
Description:
- StrToDateTime converts the string S to a TDateTime date and time value. The Date must
consist of 1 to three digits, separated by the DateSeparator character. If two numbers are
given, they are supposed to form the day and month of the current year. If only one number
is given, it is supposed to represent the day of the current month. (This is not supported in
Delphi)
The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the ShortDateFormat
variable.
-
Errors:
- On error (e.g. an invalid date or invalid character), an EConvertError exception is raised.
-
See also:
- StrToDate (728), StrToTime (729), DateTimeToStr (717)
Listing: sysutex/ex20.pp
-
Declaration:
- Function StrToTime(const S: string): TDateTime;
-
Description:
- StrToTime converts the string S to a TDateTime time value. The time must consist of 1
to 4 digits, separated by the TimeSeparator character. If two numbers are given, they are
supposed to form the hour and minutes.
-
Errors:
- On error (e.g. an invalid date or invalid character), an EConvertError exception is raised.
-
See also:
- StrToDate (728), StrToDateTime (729), TimeToStr (732)
Listing: sysutex/ex21.pp
-
Declaration:
- Function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
-
Description:
- SystemTimeToDateTime converts a TSystemTime record to a TDateTime style date/time
indication.
-
Errors:
- None.
-
See also:
- DateTimeToSystemTime (718)
Listing: sysutex/ex22.pp
-
Declaration:
- Function Time: TDateTime;
-
Description:
- Time returns the current time in TDateTime format. The date part of the TDateTimeValue
is set to zero.
-
Errors:
- None.
-
See also:
- Now (727), Date (715)
Listing: sysutex/ex23.pp
-
Declaration:
- Function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
-
Description:
- TimeStampToDateTime converts TimeStamp to a TDateTime format variable. It is the inverse
operation of DateTimeToTimeStamp (719).
-
Errors:
- None.
-
See also:
- DateTimeToTimeStamp (719), TimeStampToMSecs (732)
Listing: sysutex/ex24.pp
-
Declaration:
- Function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;
-
Description:
- TimeStampToMSecs converts TimeStamp to the number of seconds since 1/1/0001.
Use TTimeStamp variables if you need to keep very precise track of time.
-
Errors:
- None.
-
See also:
- MSecsToTimeStamp (726), TimeStampToDateTime (731)
For an example, see MSecsToTimeStamp (726).
-
Declaration:
- Function TimeToStr(Time: TDateTime): string;
-
Description:
- TimeToStr converts the time in Time to a string. It uses the ShortTimeFormat variable
to see what formatting needs to be applied. It is therefor entirely equivalent to a
FormatDateTime('t',Time) call.
-
Errors:
- None.
-
See also:
Listing: sysutex/ex25.pp