Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding days to a date

Status
Not open for further replies.

Morelos

MIS
Apr 12, 2000
33
0
0
MX
I want to add a number to a datetime component so i get the resulting date from that operation, but i don't remember the function name if there is one. Eg.: Today is 01/12/05... I need to know what date is it in 45 days. (02/26/05). So I need to add 45 days to today's date. How can I do this in Delphi with or without a function?
 
It should be as easy as YourDateTimevalue + 45. You may need to use variable to achieve this depending on the capabilities of the component.
Code:
var
  d: TDateTime;

  d := YourComponent.Value;
  d := d + 45;
  YourComponent.Value := d;
or
Code:
  YourComponent.Text := DateTimeToStr(StrToDateTime(YourComponent.Text) + 45);
 
In Delphi 6, there is a function called IncDay:
function IncDay(const AValue: TDateTime; const ANumberOfDays: Integer = 1): TDateTime;
Code:
  IncDay(dateTimeVar, 45);

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top