date in x++ Programming Language
Table of Content:
date in x++ Programming Language
The date data type contains the day, month, and year. Dates can be written as literals by using the following syntax: Date literal = day \ month \ year. You must use four digits for the year.
The date data type can hold dates between January 1, 1900, and December 31, 2154. The size of a date is 32-bits. The default value is null, and the internal representation is a date.
A date has no implicit conversions, however, the following explicit conversion functions can be used: str2date, date2str, date2num, and int2date.
You can add and subtract integers from dates, which moves the date some days into the future and past respectively. Subtracting dates from each other will calculate the difference in days, however, adding two dates together is not possible and will lead to a compiler error.
date Example
public void DateMethod() { // Simple declaration of a date variable, d. date d; // Multiple declaration of two date variables. date d1, d2; // A date variable, d3, is initialized to the 21st of November 1998. date d3 = 21\11\1998; // Declaration of a dynamic array of dates. date d4[]; // Using arithmetic operators with integer variables and dates. void myMethod() { int anInteger; date aDate; // Sets the date variable aDate to January 1, 1998. aDate = 1\1\1998; // Sets the integer variable anInteger to 30. anInteger = 30; // Uses an integer value in the computation of dates. // This sets aDate to aDate + 30; that is the 31st of January 1998. aDate = aDate + anInteger; // Create 2 variables, set bDate, and then subtract from that date. date bDate; int dateDifference; bDate = 2\10\1998; dateDifference = bDate - aDate; // dateDifference will equal 244. } }