Cursors > Generic Data Types > Handling Date and Time Values
 
Handling Date and Time Values
Date-and-time related data types are handled through different conversion protocols depending on the database systems. To achieve portability, Rogue Wave DB Link offers a feature that allows date-and-time values to be sent and retrieved as objects of the class IldDateTime.
The Rogue Wave DB Link class IldDateTime is a transparent container where you can put or get the separate components of a date-and-time value. Its fields extend the time precision to milliseconds.
Note: The millisecond precision of the class IldDateTime introduces a small discrepancy when connected to Informix, where a millionth of a second precision is possible.
After turning the date as string feature off, you can use an IldDateTime object just like any other data type.
*To put a date-and-time value into a variable, use the member function IldRequest::setParamValue, like this:
{
IldDateTime* dt = new IldDateTime(1996, 3, 2); // 1996/03/02
request->setParamValue(dt, 1);
}
*To retrieve a date-and-time value, use the function IldRequest::getColDateTimeValue, as in the following code extract:
{
// Print selected item values.
do {
if (!request->fetch())
IldDisplayError("Fetch failed:", request);
else if (request->hasTuple()) {
cout << request->getColStringValue(0) << "\t";
IldDateTime dt = request->getColDateTimeValue(1);
if (request->isErrorRaised())
IldDisplayError("Cannot retrieve DateTime: ", request);
else {
cout << dt.getYear() << "/" << dt.getMonth() << "/"
<< dt.getDay() << " " << dt.getHour() << ":"
<< dt.getMinute() << ":" << dt.getSecond() << endl;
}
}
} while (request->hasTuple());
}
These two member functions raise an error of type ILD_TYPE_MISMATCH if the date as string feature is turned on.
At creation, all fields of an IldDateTime object are initialized by default at zero.

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.