OCILIB (C and C++ Driver for Oracle)  4.7.5
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Loading...
Searching...
No Matches
ocilib::Date Class Reference

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

#include <types.hpp>

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

Public Member Functions

 Date (bool create=false)
 Create an empty null Date object.
 
 Date (const otext *str, const otext *format=OTEXT(""))
 Create a date object with the value provided by the input date time string.
 
 Date (const ostring &str, const ostring &format=OTEXT(""))
 Create a date object with the value provided by the input date time string.
 
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.
 
void SetDate (int year, int month, int day)
 Set the date part.
 
void SetTime (int hour, int min, int sec)
 Set the time part.
 
void SetDateTime (int year, int month, int day, int hour, int min, int sec)
 Set the date and time part.
 
void GetDate (int &year, int &month, int &day) const
 Extract the date parts.
 
void GetTime (int &hour, int &min, int &sec) const
 Extract time parts.
 
void GetDateTime (int &year, int &month, int &day, int &hour, int &min, int &sec) const
 Extract the date and time parts.
 
void AddDays (int days)
 Add or subtract days.
 
void AddMonths (int months)
 Add or subtract months.
 
Date NextDay (const ostring &day) const
 Return the date of next day of the week, after the current date object.
 
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.
 
void FromString (const ostring &str, const ostring &format=OTEXT(""))
 Assign to the date object the value provided by the input date time string.
 
ostring ToString (const ostring &format) const
 Convert the date value to a string using the given format.
 
ostring ToString () const override
 Convert the date value to a string using default format OCI_STRING_FORMAT_DATE.
 
Date Clone () const
 Clone the current instance to a new one performing deep copy.
 
Dateoperator++ ()
 Increment the date by 1 day.
 
Date operator++ (int)
 Increment the date by 1 day.
 
Dateoperator-- ()
 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.
 
Dateoperator+= (int value)
 Increment the date by the given number of days.
 
Dateoperator-= (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 2674 of file types.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 28 of file Date.hpp.

◆ 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 43 of file Date.hpp.

References FromString().

◆ 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 36 of file Date.hpp.

References FromString().

Member Function Documentation

◆ SysDate()

Date ocilib::Date::SysDate ( )
inlinestatic

Return the current system date time.

Definition at line 64 of file Date.hpp.

References ocilib::core::Check(), and OCI_DateSysDate().

◆ IsValid()

bool ocilib::Date::IsValid ( ) const
inline

Check if the given date is valid.

Definition at line 91 of file Date.hpp.

References ocilib::core::Check(), and OCI_DateCheck().

◆ GetYear()

int ocilib::Date::GetYear ( ) const
inline

Return the date year value.

Definition at line 96 of file Date.hpp.

References GetDate().

◆ SetYear()

void ocilib::Date::SetYear ( int  value)
inline

Set the date year value.

Definition at line 105 of file Date.hpp.

References GetDate(), and SetDate().

◆ GetMonth()

int ocilib::Date::GetMonth ( ) const
inline

Return the date month value.

Definition at line 113 of file Date.hpp.

References GetDate().

◆ SetMonth()

void ocilib::Date::SetMonth ( int  value)
inline

Set the date month value.

Definition at line 122 of file Date.hpp.

References GetDate(), and SetDate().

◆ GetDay()

int ocilib::Date::GetDay ( ) const
inline

Return the date day value.

Definition at line 130 of file Date.hpp.

References GetDate().

◆ SetDay()

void ocilib::Date::SetDay ( int  value)
inline

Set the date day value.

Definition at line 139 of file Date.hpp.

References GetDate(), and SetDate().

◆ GetHours()

int ocilib::Date::GetHours ( ) const
inline

Return the date hours value.

Definition at line 147 of file Date.hpp.

References GetTime().

◆ SetHours()

void ocilib::Date::SetHours ( int  value)
inline

Set the date hours value.

Definition at line 156 of file Date.hpp.

References GetTime(), and SetTime().

◆ GetMinutes()

int ocilib::Date::GetMinutes ( ) const
inline

Return the date minutes value.

Definition at line 164 of file Date.hpp.

References GetTime().

◆ SetMinutes()

void ocilib::Date::SetMinutes ( int  value)
inline

Set the date minutes value.

Definition at line 173 of file Date.hpp.

References GetTime(), and SetTime().

◆ GetSeconds()

int ocilib::Date::GetSeconds ( ) const
inline

Return the date seconds value.

Definition at line 181 of file Date.hpp.

References GetTime().

◆ SetSeconds()

void ocilib::Date::SetSeconds ( int  value)
inline

Set the date seconds value.

Definition at line 190 of file Date.hpp.

References GetTime(), and SetTime().

◆ 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 198 of file Date.hpp.

References ocilib::core::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 203 of file Date.hpp.

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

Referenced by SetDay(), SetMonth(), and SetYear().

◆ 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 208 of file Date.hpp.

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

Referenced by SetHours(), SetMinutes(), and SetSeconds().

◆ 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 213 of file Date.hpp.

References ocilib::core::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 218 of file Date.hpp.

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

Referenced by GetDay(), GetMonth(), GetYear(), SetDay(), SetMonth(), and SetYear().

◆ 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 223 of file Date.hpp.

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

Referenced by GetHours(), GetMinutes(), GetSeconds(), SetHours(), SetMinutes(), and SetSeconds().

◆ 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 228 of file Date.hpp.

References ocilib::core::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 233 of file Date.hpp.

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

Referenced by operator+=(), and operator-=().

◆ AddMonths()

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

Add or subtract months.

Parameters
months- Number of months to add/remove

Definition at line 238 of file Date.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 243 of file Date.hpp.

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

◆ LastDay()

Date ocilib::Date::LastDay ( ) const
inline

Return the last day of month from the current date object.

Definition at line 252 of file Date.hpp.

References ocilib::core::Check(), Clone(), and OCI_DateLastDay().

◆ 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 261 of file Date.hpp.

References ocilib::core::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 266 of file Date.hpp.

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

Referenced by Date().

◆ 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 271 of file Date.hpp.

References ocilib::core::Check(), ocilib::core::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::core::Streamable.

Definition at line 287 of file Date.hpp.

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

Referenced by ToString().

◆ Clone()

Date ocilib::Date::Clone ( ) const
inline

Clone the current instance to a new one performing deep copy.

Definition at line 75 of file Date.hpp.

References ocilib::core::Check(), and OCI_DateAssign().

Referenced by LastDay(), NextDay(), operator+(), operator++(), operator-(), and operator--().

◆ operator++() [1/2]

Date & ocilib::Date::operator++ ( )
inline

Increment the date by 1 day.

Definition at line 292 of file Date.hpp.

◆ operator++() [2/2]

Date ocilib::Date::operator++ ( int  )
inline

Increment the date by 1 day.

Definition at line 297 of file Date.hpp.

References Clone().

◆ operator--() [1/2]

Date & ocilib::Date::operator-- ( )
inline

Decrement the date by 1 day.

Definition at line 306 of file Date.hpp.

◆ operator--() [2/2]

Date ocilib::Date::operator-- ( int  )
inline

Decrement the date by 1 day.

Definition at line 311 of file Date.hpp.

References Clone().

◆ operator+()

Date ocilib::Date::operator+ ( int  value) const
inline

Return a new date holding the current date value incremented by the given number of days.

Definition at line 320 of file Date.hpp.

References Clone().

◆ operator-()

Date ocilib::Date::operator- ( int  value) const
inline

Return a new date holding the current date value decremented by the given number of days.

Definition at line 326 of file Date.hpp.

References Clone().

◆ operator+=()

Date & ocilib::Date::operator+= ( int  value)
inline

Increment the date by the given number of days.

Definition at line 332 of file Date.hpp.

References AddDays().

◆ operator-=()

Date & ocilib::Date::operator-= ( int  value)
inline

Decrement the date by the given number of days.

Definition at line 338 of file Date.hpp.

References AddDays().

◆ operator==()

bool ocilib::Date::operator== ( const Date other) const
inline

Indicates if the current date value is equal to the given date value.

Definition at line 344 of file Date.hpp.

◆ operator!=()

bool ocilib::Date::operator!= ( const Date other) const
inline

Indicates if the current date value is not equal the given date value.

Definition at line 349 of file Date.hpp.

◆ operator>()

bool ocilib::Date::operator> ( const Date other) const
inline

Indicates if the current date value is superior to the given date value.

Definition at line 354 of file Date.hpp.

◆ operator<()

bool ocilib::Date::operator< ( const Date other) const
inline

Indicates if the current date value is inferior to the given date value.

Definition at line 359 of file Date.hpp.

◆ operator>=()

bool ocilib::Date::operator>= ( const Date other) const
inline

Indicates if the current date value is superior or equal to the given date value.

Definition at line 364 of file Date.hpp.

◆ operator<=()

bool ocilib::Date::operator<= ( const Date other) const
inline

Indicates if the current date value is inferior or equal to the given date value.

Definition at line 371 of file Date.hpp.