ThN
ThN

Reputation: 3278

Replacement for EncodeTime or DecodeTime in Delphi Prism

In Delphi Win32, you have EncodeTime and DecodeTime functions to manipulate DateTime data or variables. Are there any functions similar to these in DELPHI Prism? If not, How would you do it?

For instance, you wanted to Add two datetime variables (A and B) together, after increasing B by one day.

Thanks,

Upvotes: 0

Views: 318

Answers (1)

RRUZ
RRUZ

Reputation: 136391

You must use the DateTime type, this class has many constructors which you can use to encode a a datetime.

Example to encode a DateTime

Var
  ADateTime : DateTime;
begin
  //to enconde 29 August 2011
  ADateTime:=new DateTime(2011,8,29);

  //to enconde 29 August 2011 , 23:30 
  ADateTime:=new DateTime(2011,8,29,23,30,0);

To Decode a DateTime you must use the properties Year, Month, Day, Minute and Second.

  var AYear : Integer:= ADateTime.Year;
  var AMonth : Integer:= ADateTime.Month;
  var ADay : Integer:= ADateTime.Day;

Now to modify a Datetime adding days , years or another range you can use the methods AddYears, AddMonths, AddDays and so on.

//add a year to the date stored in the ADateTime variable
Var NewDateTime: DateTime:=  ADateTime.AddYears(1);

//substract a month to the date stored in the ADateTime variable
Var NewDateTime: DateTime:=  ADateTime.AddMonths(-1);

Upvotes: 2

Related Questions