Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic

Date Types

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 API provides methods and functions to allow the user to manipulate the CTDATE type in their applications.

Function

Operation

ctdbDateCheck

Returns CTDBRET_OK if it is a valid date. Month must be a value between 1 and 12 and day must be a value between 1 and 31. This function checks for dates such as February 29th for leap years and for months that have 30 and 31 days.

ctdbDatePack

Packs 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.

ctdbDateUnpack

Update a CTDATE value into year, month and day.

ctdbDateToString

Convert a packed CTDATE value into string. DateType() gives the format of the date in string form.

ctdbStringToDate

Convert a date in string format to a packed CTDATE value. DateType gives the format of the date in string form.

ctdbGetDay

Retrieve the day component of a packed date type.

ctdbGetMonth

Retrieve the month component of a packed date type.

ctdbGetYear

Retrieve the year component of a packed date type.

ctdbIsLeapYear

Indicate if the year component of the packed date type is a leap year.

ctdbDayOfWeek

Retrieve the day of the week for a given packed date type. Sunday is 0, Monday is 1, Tuesday is 2, and so on.

ctdbGetDefDateType

Retrieve the default date format type for this session. The record manager uses the session default date format type when converting date fields into string values and vice-versa.

ctdbSetDefDateType

Set the default date format type for this session. When a session handle is allocated, the default date format type is set to CTDATE_MDCY: month followed by day and year

ctdbCurrentDate

Retrieve the current system date and store it in CTDATE packed format.

Date Type Formats

The possible date formats for string conversion are:

c-treeDB API
Symbolic Constant

c-treeDB API .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