CTDATE is declared as an unsigned 32-bit integer. The date is stored as the number of days since March 1st 1700. The CTDATE type was implemented to be compatible with FairCom's r-tree and ODBC products. Hence, if a CTDATE type has a value of 1, it means that the date is March 1st 1700, while a value of 2 means March 2nd 1700 and so on.
Since CTDATE is a 32-bit unsigned integer, numerical operations with dates can be done using standard C operators. For example, to add 10 days to a date use the normal C operation date + 10 (assuming that date is a CTDATE type). To get the difference in days of 2 dates, just subtract one date from another.
c-treeDB provides methods and functions to allow the user to manipulate the CTDATE type in their applications.
Method |
Operation |
---|---|
Pack |
Pack a date as year, month and day and store the result in pDate. The date is checked and ctdbDatePack() returns CTDBRET_OK if the date was packed correctly. |
Unpack |
Update a CTDATE value into year, month and day. |
ToString |
Convert a packed CTDATE value into string. The format of the date in string form is given by DateType(). |
StringToDate |
Convert a date in string format to a packed CTDATE value. The format of the date in string form is given by DateType() as described above. |
Day |
Retrieve the day component of a packed date type. |
Month |
Retrieve the month component of a packed date type. |
Year |
Retrieve the year component of a packed date type. |
IsLeapYear |
Indicate if the year component of the packed date type is a leap year. |
DayOfWeek |
Retrieve the day of the week for a given packed date type. Sunday is 0, Monday is 1, Tuesday is 2, and so on. |
CurrentDate |
Retrieve the current system date and store it in CTDATE packed format. |
The possible date formats for string conversion are:
c-treeDB |
c-treeDB .NET |
|
CTDATE_MDCY |
MDCY_DATE |
Date is mm/dd/ccyy |
CTDATE_MDY |
MDY_DATE |
Date is mm/dd/yy |
CTDATE_DMCY |
DMCY_DATE |
Date is dd/mm/ccyy |
CTDATE_DMY |
DMY_DATE |
Date is dd/mm/yy |
CTDATE_CYMD |
CYMD_DATE |
Date is ccyymmdd |
CTDATE_YMD |
YMD_DATE |
Date is yymmdd |