ocilib::Date Class Reference

Object identifying the SQL data type DATE. More...

`#include <ocilib.hpp>`

Inherits ocilib::HandleHolder< OCI_Date *>, and ocilib::Streamable.

## Public Member Functions

| Date (bool create=false)
| Create an empty null Date object. More...
| Date (const otext *str, const otext *format=OTEXT(""))
| Create a date object with the value provided by the input date time string. More...
| Date (const ostring &str, const ostring &format=OTEXT(""))
| Create a date object with the value provided by the input date time string. More...
bool | IsValid () const
| Check if the given date is valid.
int | GetYear () const
| Return the date year value.
void | SetYear (int value)
| Set the date year value.
int | GetMonth () const
| Return the date month value.
void | SetMonth (int value)
| Set the date month value.
int | GetDay () const
| Return the date day value.
void | SetDay (int value)
| Set the date day value.
int | GetHours () const
| Return the date hours value.
void | SetHours (int value)
| Set the date hours value.
int | GetMinutes () const
| Return the date minutes value.
void | SetMinutes (int value)
| Set the date minutes value.
int | GetSeconds () const
| Return the date seconds value.
void | SetSeconds (int value)
| Set the date seconds value.
int | DaysBetween (const Date &other) const
| Return the number of days with the given date. More...
void | SetDate (int year, int month, int day)
| Set the date part. More...
void | SetTime (int hour, int min, int sec)
| Set the time part. More...
void | SetDateTime (int year, int month, int day, int hour, int min, int sec)
| Set the date and time part. More...
void | GetDate (int &year, int &month, int &day) const
| Extract the date parts. More...
void | GetTime (int &hour, int &min, int &sec) const
| Extract time parts. More...
void | GetDateTime (int &year, int &month, int &day, int &hour, int &min, int &sec) const
| Extract the date and time parts. More...
void | AddDays (int days)
| Add or subtract days. More...
void | AddMonths (int months)
| Add or subtract months. More...
Date | NextDay (const ostring &day) const
| Return the date of next day of the week, after the current date object. More...
Date | LastDay () const
| Return the last day of month from the current date object.
void | ChangeTimeZone (const ostring &tzSrc, const ostring &tzDst)
| Convert the date from one zone to another zone. More...
void | FromString (const ostring &str, const ostring &format=OTEXT(""))
| Assign to the date object the value provided by the input date time string. More...
ostring | ToString (const ostring &format) const
| Convert the date value to a string using the given format. More...
ostring | ToString () const override
| Convert the date value to a string using default format OCI_STRING_FORMAT_DATE. More...
Date | Clone () const
| Clone the current instance to a new one performing deep copy.
Date & | operator++ ()
| Increment the date by 1 day.
Date | operator++ (int)
| Increment the date by 1 day.
Date & | operator-- ()
| Decrement the date by 1 day.
Date | operator-- (int)
| Decrement the date by 1 day.
Date | operator+ (int value) const
| Return a new date holding the current date value incremented by the given number of days.
Date | operator- (int value) const
| Return a new date holding the current date value decremented by the given number of days.
Date & | operator+= (int value)
| Increment the date by the given number of days.
Date & | operator-= (int value)
| Decrement the date by the given number of days.
bool | operator== (const Date &other) const
| Indicates if the current date value is equal to the given date value.
bool | operator!= (const Date &other) const
| Indicates if the current date value is not equal the given date value.
bool | operator> (const Date &other) const
| Indicates if the current date value is superior to the given date value.
bool | operator< (const Date &other) const
| Indicates if the current date value is inferior to the given date value.
bool | operator>= (const Date &other) const
| Indicates if the current date value is superior or equal to the given date value.
bool | operator<= (const Date &other) const
| Indicates if the current date value is inferior or equal to the given date value.

## Static Public Member Functions

static Date | SysDate ()
| Return the current system date time.

## Detailed Description

Object identifying the SQL data type DATE.

This class wraps the OCILIB object handle OCI_Date and its related methods

Definition at line 2677 of file ocilib.hpp.

## Constructor & Destructor Documentation

## Date() [1/3]

ocilib::Date::Date | ( | bool | create = `false` | ) |

inline

Create an empty null Date object.

Parameters

  create | - Indicates if a Oracle Date object must be must be created

Definition at line 1965 of file ocilib_impl.hpp.

Referenced by Date().

## Date() [2/3]

ocilib::Date::Date | ( | const otext * | str,
|  | const otext * | format = `OTEXT("")`
| ) |  |

inline

Create a date object with the value provided by the input date time string.

Parameters

  str | - String date time
  format | - format of the date time provided in parameter 'data'

Note
  For date time formats, refer to the Oracle SQL documentation
  Default connection date format is computed from Environment::GetFormat()

Definition at line 1980 of file ocilib_impl.hpp.

References ocilib::Check(), Date(), OCI_DateCreate(), and OCI_DateFree().

## Date() [3/3]

ocilib::Date::Date | ( | const ostring & | str,
|  | const ostring & | format = `OTEXT("")`
| ) |  |

inline

Create a date object with the value provided by the input date time string.

Parameters

  str | - String date time
  format | - format of the date time provided in parameter 'data'

Note
  For date time formats, refer to the Oracle SQL documentation
  Default connection date format is computed from Environment::GetFormat()

Definition at line 1973 of file ocilib_impl.hpp.

## Member Function Documentation

## DaysBetween()

int ocilib::Date::DaysBetween | ( | const Date & | other | ) | const

inline

Return the number of days with the given date.

Parameters

  other | - date to compare

Definition at line 2131 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_DateDaysBetween().

## SetDate()

void ocilib::Date::SetDate | ( | int | year,
|  | int | month,
|  | int | day
| ) |  |

inline

Set the date part.

Parameters

  year | - Year value
  month | - Month value
  day | - Day value

Definition at line 2136 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_DateSetDate().

## SetTime()

void ocilib::Date::SetTime | ( | int | hour,
|  | int | min,
|  | int | sec
| ) |  |

inline

Set the time part.

Parameters

  hour | - Hour value
  min | - Minute value
  sec | - Second value

Definition at line 2141 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_DateSetTime().

## SetDateTime()

void ocilib::Date::SetDateTime | ( | int | year,
|  | int | month,
|  | int | day,
|  | int | hour,
|  | int | min,
|  | int | sec
| ) |  |

inline

Set the date and time part.

Parameters

  year | - Year value
  month | - Month value
  day | - Day value
  hour | - Hour value
  min | - Minute value
  sec | - Second value

Definition at line 2146 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_DateSetDateTime().

## GetDate()

void ocilib::Date::GetDate | ( | int & | year,
|  | int & | month,
|  | int & | day
| ) |  | const

inline

Extract the date parts.

Parameters

  year | - Place holder for year value
  month | - Place holder for month value
  day | - Place holder for day value

Definition at line 2151 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_DateGetDate().

## GetTime()

void ocilib::Date::GetTime | ( | int & | hour,
|  | int & | min,
|  | int & | sec
| ) |  | const

inline

Extract time parts.

Parameters

  hour | - Place holder for hour value
  min | - Place holder for minute value
  sec | - Place holder for second value

Definition at line 2156 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_DateGetTime().

## GetDateTime()

void ocilib::Date::GetDateTime | ( | int & | year,
|  | int & | month,
|  | int & | day,
|  | int & | hour,
|  | int & | min,
|  | int & | sec
| ) |  | const

inline

Extract the date and time parts.

Parameters

  year | - Place holder for year value
  month | - Place holder for month value
  day | - Place holder for day value
  hour | - Place holder for hour value
  min | - Place holder for minute value
  sec | - Place holder for second value

Definition at line 2161 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_DateGetDateTime().

## AddDays()

void ocilib::Date::AddDays | ( | int | days | ) |

inline

Add or subtract days.

Parameters

  days | - Number of days to add/remove

Definition at line 2166 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_DateAddDays().

## AddMonths()

void ocilib::Date::AddMonths | ( | int | months | ) |

inline

Add or subtract months.

Parameters

  months | - Number of months to add/remove

Definition at line 2171 of file ocilib_impl.hpp.

References OCI_DateAddMonths().

## NextDay()

Date ocilib::Date::NextDay | ( | const ostring & | day | ) | const

inline

Return the date of next day of the week, after the current date object.

Parameters

  day | - Day of the week

Definition at line 2176 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_DateNextDay().

## ChangeTimeZone()

void ocilib::Date::ChangeTimeZone | ( | const ostring & | tzSrc,
|  | const ostring & | tzDst
| ) |  |

inline

Convert the date from one zone to another zone.

Parameters

  tzSrc | - Source zone
  tzDst | - Destination zone

Definition at line 2194 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_DateZoneToZone().

## FromString()

void ocilib::Date::FromString | ( | const ostring & | str,
|  | const ostring & | format = `OTEXT("")`
| ) |  |

inline

Assign to the date object the value provided by the input date time string.

Parameters

  str | - String date time
  format | - format of the date time provided in parameter 'data'

Note
  For date time formats, refer to the Oracle SQL documentation
  Default connection date format is computed from Environment::GetFormat()

Definition at line 2199 of file ocilib_impl.hpp.

References ocilib::Check(), ocilib::FormatDate, ocilib::Environment::GetFormat(), and OCI_DateFromText().

## ToString() [1/2]

ostring ocilib::Date::ToString | ( | const ostring & | format | ) | const

inline

Convert the date value to a string using the given format.

Parameters

  format | - date time format to use

Note
  For date time formats, refer to the Oracle SQL documentation

Definition at line 2204 of file ocilib_impl.hpp.

References ocilib::Check(), ocilib::MakeString(), and OCI_DateToText().

## ToString() [2/2]

ostring ocilib::Date::ToString | ( |  | ) | const

inlineoverridevirtual

Convert the date value to a string using default format OCI_STRING_FORMAT_DATE.

Note
  For date time formats, refer to the Oracle SQL documentation

Implements ocilib::Streamable.

Definition at line 2220 of file ocilib_impl.hpp.

References ocilib::FormatDate, and ocilib::Environment::GetFormat().