Product Documentation

c-treeDB API for C# - Developers Guide

Previous Topic

Next Topic

Date Types

CTDATE is declared as an unsigned 32-bit integer stored as the number of days since March 1st 1700. It is compatible with FairCom’s r-tree and ODBC products. A CTDATE value of 1 matches the date March 1st 1700, a value of 2 means March 2nd 1700, etc.

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 two dates, just subtract one date from another.

c-treeDB .NET provides the class CTDate that exposes the following set of methods to allow manipulation of the CTDATE type in 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.

Date formats for string conversion are defined in the DATE_TYPE enum and are shown in the following table.

The possible date formats for string conversion are:

c-treeDB
Symbolic Constant

c-treeDB .NET
Symbolic Constant


Description

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

TOCIndex