Delphi operation date variable + 1-1

Source: Internet
Author: User

 

Transferred from: original article link

 

 

Demand: Increase by year (month, day)
Declaration: function incyear (const startdate: tdatetime {; numberofyears: integer = 1}): tdatetime;

Description: The incyear function adds the number of years of numberofyears to the startdatetime parameter passed in.

The increase or decrease quantity is optional. The default value is 1.

After the year is added, if the number of days is too large for the current year and month, it is automatically reduced to the maximum date value of the current year and month.

Example:
Incyear (now); // the current date plus one year
Incyear (now, 5); // the current date plus 5 years
Incyear (now,-1); // the current date minus 1 year

The incmonth () function is called when the month is to be operated, and the incday () function is called when the day is manipulated. The usage is similar.
There are also incweek (), inchour (), incminute (), incsecond () and so on.

Note: There is no decyear function. On the contrary, a negative number is used in incyear to Increase the number.

Requirement: Add 1 or N (minus 1 or minus N) to I in a loop)
INC () or Dec ();
Example
Procedure tform1.test ();
VaR
I: integer;
Begin
I: = 0;
For Y: = 0 to 100 do
Begin
INC (I); // each time to I + 1;
INC (I, 5); // each time I + 5;
Dec (I); // each time to the I-1;
Dec (I, 5); // each time to the I-5;
End;
End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.