Skip Headers

Oracle C++ Call Interface Programmer's Guide
Release 2 (9.2)

Part Number A96583-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to beginning of chapter Go to next page

OCCI Classes and Methods, 8 of 22


Date Class

The Date class specifies the abstraction for a SQL DATE data item. The Date class also adds formatting and parsing operations to support the OCCI escape syntax for date values.

Since SQL92 DATE is a subset of Oracle Date, this class can be used to support both.

To create a null Date object, use the syntax:

Date();

To create a copy of a Date object, use the syntax:

Date(const Date &a);

To create a Date object using integer parameters, where:

Variable Value

year

-4712 to 9999, except 0

month

1 to 12

day

1 to 31

minutes

0 to 59

seconds

0 to 59

use the syntax:

Date(const Environment *envp,
   int year = 1,
   unsigned int month = 1,
   unsigned int day = 1,
   unsigned int hour = 0,
   unsigned int minute = 0,
   unsigned int seconds = 0);

Objects from the Date class can be used as standalone class objects in client side numerical computations and also used to fetch from and set to the database.

The following code example demonstrates a Date column value being retrieved from the database, a bind using a Date object, and a computation using a standalone Date object:

/* Create a connection */
Environment *env = Environment::createEnvironment(Environment::DEFAULT);
Connection *conn = env->createConnection(user, passwd, db);

/* Create a statement and associate a DML statement to it */
string sqlStmt = "SELECT job-id, start_date from JOB_HISTORY
                            where end_date = :x";
Statement *stmt = conn->createStatement(sqlStmt);

/* Create a Date object and bind it to the statement */
Date edate(env, 2000, 9, 3, 23, 30, 30);
stmt->setDate(1, edate);
ResultSet *rset = stmt->executeQuery();

/* Fetch a date from the database */
while(rset->next())
{
   Date sd = rset->getDate(2);
   Date temp = sd;    /*assignment operator */
   /* Methods on Date */
   temp.getDate(year, month, day, hour, minute, second);
   temp.setMonths(2);
   IntervalDS inter = temp.daysBetween(sd);
   .
   .
   .
}

Summary of Date Methods

Table 8-8 Date Methods  
Method Summary

addDays()

Return a Date object with n days added.

addMonths()

Return a Date object with n months added.

daysBetween()

Return the number of days between the current Date object and the date specified.

fromBytes()

Convert an external Bytes representation of a Date object to a Date object.

fromText()

Convert the date from a given input string with format and nls parameters specified.

getDate()()

Return the date and time components of the Date object.

getSystemDate()

Return a Date object containing the system date.

isNull()

Returns true if Date is null; otherwise returns false.

lastDay()

Returns a Date that is the last day of the month.

nextDay()

Returns a Date that is the date of the next day of the week.

operator=()

Assign the values of a date to another.

operator==()

Returns true if a and b are the same, false otherwise.

operator!=()

Returns true if a and b are unequal, false otherwise.

operator>()

Returns true if a is past b, false otherwise.

operator>=()

Returns true if a is past b or equal to b, false otherwise.

operator<()

Returns true if a is before b, false otherwise.

operator<=()

Returns true if a is before b, or equal to b, false otherwise.

setDate()

Set the date from the date components input.

setNull()

Sets the object state to null.

toBytes()

Converts the Date object into an external Bytes representation.

toText()

Get the Date object as a string.

toZone()

Return a Date object converted from one time zone to another.

addDays()

This method adds a specified number of days to the Date object and returns the new date.

Syntax
Date addDays(int i) const;
Parameters
i

The number of days to be added to the current Date object.

addMonths()

This method adds a specified number of months to the Date object and returns the new date.

Syntax
Date addMonths(int i) const;
Parameters
i

The number of months to be added to the current Date object.

daysBetween()

This method returns the number of days between the current Date object and the date specified.

Syntax
IntervalDS daysBetween(const Date &d) const;
Parameters
d

The date to be used to compute the days between.

fromBytes()

This method converts a Bytes object to a Date object.

Syntax
void fromBytes(const Bytes &byteStream,
const Environment *envp = NULL);
Parameters
byteStream

Date in external format in the form of Bytes.

envp

The OCCI environment.

fromText()

This method converts a string object to a Date object.

Syntax
void fromText(const string &datestr,
   const string &fmt = "",
   const string &nlsParam = "",
   const Environment *envp = NULL);
Parameters
datestr

The date string to be converted.

fmt

The format string.

nlsParam

A string specifying the nls parameters to be used.

envp

The environment from which the nls parameters are to be obtained.

getDate()

This method returns the date in the form of the date components year, month, day, hour, minute, seconds.

Syntax
void getDate(int &year,
   unsigned int &month,
   unsigned int &day,
   unsigned int &hour,
   unsigned int &min,
   unsigned int &sec) const;
Parameters
year

The year component of the date.

month

The month component of the date.

day

The day component of the date.

hour

The hour component of the date.

min

The minutes component of the date.

seconds

The seconds component of the date.

getSystemDate()

This method returns the system date.

Syntax
static Date getSystemDate(const Environment *envp);
Parameters
envp

The environment in which the system date is returned.

isNull()

This method tests whether the Date is null. If the Date is null, true is returned; otherwise, false is returned.

Syntax
bool isNull() const;

lastDay()

This method returns a date representing the last day of the current month.

Syntax
Date lastDay() const;

nextDay()

This method returns a date representing the day after the day of the week specified.

Syntax
Date nextDay(const string &dow) const;
Parameters
dow

A string representing the day of the week.

operator=()

This method assigns the date object on the right side of the equal (=) sign to the date object on the left side of the equal (=) sign.

Syntax
Date& operator=(const Date &d);
Parameters
d

The date object that is assigned.

operator==()

This method compares the dates specified. If the dates are equal, true is returned; otherwise, false is returned.

Syntax
bool operator==(const Date &a,
   const Date &b);
Parameters
a, b

The dates that are compared for equality.

operator!=()

This method compares the dates specified. If the dates are not equal then true is returned; otherwise, false is returned.

Syntax
bool operator!=(const Date &a,
   const Date &b);
Parameters
a, b

The dates that are compared for inequality.

operator>()

This method compares the dates specified. If the first date is in the future relative to the second date then true is returned; otherwise, false is returned. If either date is null then false is returned. If the dates are not the same type then false is returned.

Syntax
bool operator>(const Date &a,
   const Date &b);
Parameters
a, b

The dates that are compared.

operator>=()

This method compares the dates specified. If the first date is in the future relative to the second date or the dates are equal then true is returned; otherwise, false is returned. If either date is null then false is returned. If the dates are not the same type then false is returned.

Syntax
bool operator>=(const Date &a,
   const Date &b);
Parameters
a, b

The dates that are compared.

operator<()

This method compares the dates specified. If the first date is in the past relative to the second date then true is returned; otherwise, false is returned. If either date is null then false is returned. If the dates are not the same type then false is returned.

Syntax
bool operator<(const Date &a,
   const Date &b);
Parameters
a, b

The dates that are compared.

operator<=()

This method compares the dates specified. If the first date is in the past relative to the second date or the dates are equal then true is returned; otherwise, false is returned. If either date is null then false is returned. If the dates are not the same type then false is returned.

Syntax
bool operator<=(const Date &a,
   const Date &b);
Parameters
a, b

The dates that are compared.

setDate()

This method sets the date to the values specified.

Syntax
void setDate(int year = 1,
   unsigned int month = 1,
   unsigned int day = 1,
   unsigned int hour = 0,
   unsigned int minute = 0,
   unsigned int seconds = 0);
Parameters
year

The argument specifying the year value.

Valid values are -4713 through 9999.

month

The argument specifying the month value.

Valid values are 1 through 12.

day

The argument specifying the day value.

Valid values are 1 through 31.

hour

The argument specifying the hour value.

Valid values are 0 through 23.

minute

The argument specifying the minutes value.

Valid values are 0 through 59 .

seconds

The argument specifying the seconds value.

Valid values are 0 through 59.

setNull()

This method set the date to atomically null.

Syntax
void setNull();

toBytes()

This method returns the date in Bytes representation.

Syntax
Bytes toBytes() const;

toText()

This method returns a string with the value of this date formatted using fmt and nlsParam.

Syntax
string toText(const string &fmt = "",
   const string &nlsParam = "") const;
Parameters
fmt

The format string.

nlsParam

A string specifying the nls parameters to be used.

toZone()

This method returns Date value converted from one time zone to another.

Valid values are:

Zone code Value

AST, ADT

Atlantic Standard or Daylight Time

BST, BDT

Bering Standard or Daylight Time

CST, CDT

Central Standard or Daylight Time

EST, EDT

Eastern Standard or Daylight Time

GMT

Greenwich Mean Time

HST, HDT

Alaska-Hawaii Standard Time or Daylight Time

MST, MDT

Mountain Standard or Daylight Time

NST

Newfoundland Standard Time

PST, PDT

Pacific Standard or Daylight Time

YST, YDT

Yukon Standard or Daylight Time

Syntax
Date toZone(const string &zone1,
   const string &zone2) const;
Parameters
zone1

A string representing the time zone to be converted from.

zone2

A string representing the time zone to be converted to.


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 2001, 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback