type TDateFormat =( dfShortDate, dfLongDate );
Date formats available to use in formatting date/time to string.
type TTimeFormatFlag =( tffNoMinutes, tffNoSeconds, tffNoMarker, tffForce24 );
Additional flags, used for formatting time.
type TTimeFormatFlags = Set of TTimeFormatFlag;
Set of flags, used for formatting time.
var MonthDays: array[ Boolean ] of TDayTable =(( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ),( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ) );
The MonthDays array can be used to quickly find the number of days in a month: MonthDays[IsLeapYear(Y), M].
Seconds per day.
var MSecsPerDay = SecsPerDay* 1000;
Milliseconds per day.
var VCLDate0 = 693594;
Value to convert VCL "date 0" to KOL "date 0" and back. This value corresponds to 30-Dec-1899, 0:00:00. So, to convert VCL date to KOL date, just subtract this value from VCL date. And to convert back from KOL date to VCL date, add this value to KOL date.
function Now: TDateTime;
Returns local date and time on running PC.
function Date: TDateTime;
Returns today local date.
procedure DecodeDateFully( DateTime: TDateTime; var Year, Month, Day, DayOfWeek: WORD );
Decodes date string and day of the week.
procedure DecodeDate( DateTime: TDateTime; var Year, Month, Day: WORD );
Decodes date.
function EncodeDate( Year, Month, Day: WORD; var DateTime: TDateTime ): Boolean;
Encodes date and time.
function CompareSystemTime( const D1, D2: TSystemTime ): Integer;
Compares to TSystemTime records. Returns -1, 0, or 1 if, correspondantly, D1 < D2, D1 = D2 and D1 > D2.
procedure IncDays( var SystemTime: TSystemTime; DaysNum: Integer );
Increases/decreases day in TSystemTime record onto given days count (can be negative).
procedure IncMonths( var SystemTime: TSystemTime; MonthsNum: Integer );
Increases/decreases month number in TSystemTime record onto given months count (can be negative). Correct result is not garantee if day number is incorrect for newly obtained month.
function IsLeapYear( Year: Integer ): Boolean;
Returns True, if given year is "leap" (i.e. has 29 days in the February).
function DayOfWeek( Date: TDateTime ): Integer;
Returns day of week (0..6) for given date.
function SystemTime2DateTime( const SystemTime: TSystemTime; var DateTime: TDateTime ): Boolean;
Converts TSystemTime record to XDateTime variable.
function DateTime2SystemTime( const DateTime: TDateTime; var SystemTime: TSystemTime ): Boolean;
Converts TDateTime variable to TSystemTime record.
function DateTime_System2Local( DTSys: TDateTime ): TDateTime;
Converts DTSys representing system time (+0 Grinvich) to local time.
function DateTime_Local2System( DTLoc: TDateTime ): TDateTime;
Converts DTLoc representing local time to system time (+0 Grinvich)
function FileTime2DateTime( const ft: TFileTime; var DT: TDateTime ): Boolean;
function DateTime2FileTime( DT: TDateTime; var ft: TFileTime ): Boolean;
procedure DivMod( Dividend: Integer; Divisor: Word; var Result, Remainder: Word );
Dividing of integer onto divisor with obtaining both result of division and remainder.
function SystemDate2Str( const SystemTime: TSystemTime; const LocaleID: DWORD; const DfltDateFormat: TDateFormat; const DateFormat: PKOLChar ): KOLString;
Formats date, stored in TSystemTime record into string, using given locale and date/time formatting flags. (E.g.: GetUserDefaultLangID).
function SystemTime2Str( const SystemTime: TSystemTime; const LocaleID: DWORD; const Flags: TTimeFormatFlags; const TimeFormat: PKOLChar ): KOLString;
Formats time, stored in TSystemTime record into string, using given locale and date/time formatting flags.
function Date2StrFmt( const Fmt: KOLString; D: TDateTime ): KOLString;
Represents date as a string correspondently to Fmt formatting string. See possible pictures in definition of the function Str2DateTimeFmt (the first part). If Fmt string is empty, default system date format for short date string used.
function Time2StrFmt( const Fmt: KOLString; D: TDateTime ): KOLString;
Represents time as a string correspondently to Fmt formatting string. See possible pictures in definition of the function Str2DateTimeFmt (the second part). If Fmt string is empty, default system time format for short date string used.
function DateTime2StrShort( D: TDateTime ): KOLString;
Formats date and time to string in short date format using current user locale.
function Str2DateTimeFmt( const sFmtStr, sS: KOLString ): TDateTime;
Restores date or/and time from string correspondently to a format string.
Date and time formatting string can contain following pictures (case sensitive):
DATE PICTURES |
|
d |
Day of the month as digits without leading zeros for single digit days. |
dd |
Day of the month as digits with leading zeros for single digit days |
ddd |
Day of the week as a 3-letter abbreviation as specified by a LOCALE_SABBREVDAYNAME value. |
dddd |
Day of the week as specified by a LOCALE_SDAYNAME value. |
M |
Month as digits without leading zeros for single digit months. |
MM |
Month as digits with leading zeros for single digit months |
MMM |
Month as a three letter abbreviation as specified by a LOCALE_SABBREVMONTHNAME value. |
MMMM |
Month as specified by a LOCALE_SMONTHNAME value. |
y |
Year represented only be the last digit. |
yy |
Year represented only be the last two digits. |
yyyy |
Year represented by the full 4 digits. |
gg |
Period/era string as specified by the CAL_SERASTRING value. The gg format picture in a date string is ignored if there is no associated era string. In Enlish locales, usual values are BC or AD. |
TIME PICTURES |
|
h |
Hours without leading zeros for single-digit hours (12-hour clock). |
hh |
Hours with leading zeros for single-digit hours (12-hour clock). |
H |
Hours without leading zeros for single-digit hours (24-hour clock). |
HH |
Hours with leading zeros for single-digit hours (24-hour clock). |
m |
Minutes without leading zeros for single-digit minutes. |
mm |
Minutes with leading zeros for single-digit minutes. |
s |
Seconds without leading zeros for single-digit seconds. |
ss |
Seconds with leading zeros for single-digit seconds. |
t |
One character–time marker string (usually P or A, in English locales). |
tt |
Multicharacter–time marker string (usually PM or AM, in English locales). |
E.g., 'D, yyyy/MM/dd h:mm:ss'. See also Str2DateTimeShort function. |
function Str2TimeFmt( const sFmtStr, sS: KOLString ): TDateTime;
Same as above but for time only
function Str2DateTimeShort( const S: KOLString ): TDateTime;
Restores date and time from string correspondently to current user locale.
function Str2DateTimeShortEx( const S: KOLString ): TDateTime;
Like Str2DateTimeShort above, but uses locale defined date and time separators to avoid recognizing time as a date in some cases.
function Str2TimeShort( const S: KOLString ): TDateTime;
Like Str2DateTimeShort but for time only.