# TDateTime to QDateTime

So, you need to convert the TDateTime type used in Delphi to the QDateTime Qt type.

TDateTime is a floating-point number, where the integer part is the number of days from December 30, 1899 to the current day, and the fractional part is the number of seconds from the beginning of the day.

QDateTime Converter :: fromTDateTime (double tDateTime)

{

int time_t = (int) ((tDateTime - 25569.16666) * 86400); // got the time in the format time_t

return QDateTime :: fromTime_t (time_t);

}

25569.16666 is January 1, 1970 in TDateTime format.

86400 - the number of seconds in one day.

In a real program, we replace both magic numbers with constants.

The inverse transform is performed in the reverse order.

TDateTime is a floating-point number, where the integer part is the number of days from December 30, 1899 to the current day, and the fractional part is the number of seconds from the beginning of the day.

QDateTime Converter :: fromTDateTime (double tDateTime)

{

int time_t = (int) ((tDateTime - 25569.16666) * 86400); // got the time in the format time_t

return QDateTime :: fromTime_t (time_t);

}

25569.16666 is January 1, 1970 in TDateTime format.

86400 - the number of seconds in one day.

In a real program, we replace both magic numbers with constants.

The inverse transform is performed in the reverse order.