Mega Code Archive

 
Categories / Delphi / Types
 

Tdatetime - data type holding a date and time value

type TDateTime = type Double; Description The TDateTime type holds a date and time value. It is stored as a Double variable, with the date as the integral part, and time as fractional part. The date is stored as the number of days since 30 Dec 1899. Quite why it is not 31 Dec is not clear. 01 Jan 1900 has a days value of 2. Because TDateTime is actually a double, you can perform calculations on it as if it were a number. This is useful for calculations such as the difference between two dates. Notes No local time information is held with TDateTime - just the day and time values. Related commands DateTimeToFileDate Convert a TDateTime value to a File date/time format DateTimeToStr Converts TDateTime date and time values to a string DateTimeToString Rich formatting of a TDateTime variable into a string PDateTime Pointer to a TDateTime value StrToDateTime Converts a date+time string into a TDateTime value Example code : Finding the difference between two dates var day1, day2 : TDateTime; diff : Double; begin day1 := StrToDate('12/06/2002'); day2 := StrToDate('12/07/2002'); ShowMessage('day1 = '+DateToStr(day1)); ShowMessage('day2 = '+DateToStr(day2)); diff := day2 - day1; ShowMessage('day2 - day1 = '+FloatToStr(diff)+' days'); end; Show full unit code day1 = 12/06/2002 day2 = 12/07/2002 day2 - day1 = 30 days