IBPP::Date

The IBPP::Date class represents a date value. It is not an interface class, with automatic smart pointer management like for instance the Database class. It is a plain classical C++ class. Use it to interact easily with DATE (SQL) columns in your databases.

Definition

See the file ibpp.h for an up-to-date definition.

A Date is internally made of a simple integer, representing the numbers of days elapsed since the 31 december 1899 (which means the 1 january 1900 value is 1). Being made only of an integer as its data part, the class Date is a light object which you can use without fear of bulky data structures.

Methods

void Clear()

Resets the date to an invalid value (actually -1), effectively clearing the value.

void Today()

Sets the date to today's date.

void SetDate(int year, int month, int day)

Sets the date based on the numeric values of the year, month and day. Any invalid values will lead to an invalid date value (-1).

SetDate(int dt)

Sets the date based on a integer value, as the one internally stored in the date object itself. See the int GetDate() method too.

void GetDate(int& year, int& month, int& day)

Gets a date in its basic components year, month, day.

int GetDate()

Returns the internal integer representing the date value.

int Year(), int Month(), int Day()

Returns the year, month, day value of the Date.

void Add(int days)

Add days to a date. The new date is the original one, 'days' later. This of course takes care of everything, overlapping months and years, months or different numbers of days, leap years,…

void StartOfMonth()

Adjust a date to the first day of the same month.

void EndOfMonth()

Adjust a date to the last day of the same month, taking into consideration months of varying number of days, including leap years support.

Constructors

Date()

The default constructructor builds an empty date (invalid value), same as if Clear() was called on an existing date.

Date(int dt)

Similarly to the SetDate(int) method, this form of the constructor builds a date out of the internal representation of another one.

Date(int year, int month, int day)

Similarly to the SetDate(int, int, int) method, this form of the constructor builds a date our of its basic components (year, month, day).

Date(const Date&)

Ordinary copy constructor. To make the Date a good citizen of your code.

Operators

Date& operator=(const Date&)

To assign a date from another one.

Date& operator=(const Timestamp&)

To assign a date from the date portion of a Timestamp object.

bool operator==(const Date&)

To compare two Dates for equality.

bool operator<(const Date&)

To compare if one Date is strictly 'lower' (the date is before) the other.

See also

These classes are closely related to this one :

reference/date.txt · Last modified: 2006/03/30 18:32 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki