MySQL++  3.3.0
Public Member Functions | List of all members
mysqlpp::Date Class Reference

C++ form of SQL's DATE type. More...

#include <datetime.h>

Inheritance diagram for mysqlpp::Date:
Inheritance graph
[legend]
Collaboration diagram for mysqlpp::Date:
Collaboration graph
[legend]

Public Member Functions

 Date ()
 Default constructor.
 
 Date (unsigned short y, unsigned char m, unsigned char d)
 Initialize object. More...
 
 Date (const Date &other)
 Initialize object as a copy of another Date.
 
 Date (const DateTime &other)
 Initialize object from date part of date/time object.
 
 Date (const char *str)
 Initialize object from a C string containing a date. More...
 
template<class Str >
 Date (const Str &str)
 Initialize object from a C++ string containing a date. More...
 
 Date (time_t t)
 Initialize object from a time_t. More...
 
int compare (const Date &other) const
 Compare this date to another. More...
 
const char * convert (const char *)
 Parse a SQL date string into this object.
 
unsigned char day () const
 Get the date's day part, 1-31.
 
void day (unsigned char d)
 Change the date's day part, 1-31.
 
unsigned char month () const
 Get the date's month part, 1-12.
 
void month (unsigned char m)
 Change the date's month part, 1-12.
 
 operator std::string () const
 Convert to std::string.
 
 operator time_t () const
 Convert to time_t. More...
 
std::string str () const
 Return our value in std::string form.
 
unsigned short year () const
 Get the date's year part. More...
 
void year (unsigned short y)
 Change the date's year part. More...
 
- Public Member Functions inherited from mysqlpp::Comparable< Date >
bool operator== (const Date &other) const
 Returns true if "other" is equal to this object.
 
bool operator!= (const Date &other) const
 Returns true if "other" is not equal to this object.
 
bool operator< (const Date &other) const
 Returns true if "other" is less than this object.
 
bool operator<= (const Date &other) const
 Returns true if "other" is less than or equal to this object.
 
bool operator> (const Date &other) const
 Returns true if "other" is greater than this object.
 
bool operator>= (const Date &other) const
 Returns true if "other" is greater than or equal to this object.
 

Additional Inherited Members

- Protected Member Functions inherited from mysqlpp::Comparable< Date >
virtual ~Comparable ()
 Destroy object. More...
 

Detailed Description

C++ form of SQL's DATE type.

Objects of this class can be inserted into streams, and initialized from SQL DATE strings.

Constructor & Destructor Documentation

◆ Date() [1/4]

mysqlpp::Date::Date ( unsigned short  y,
unsigned char  m,
unsigned char  d 
)
inline

Initialize object.

Parameters
yyear, 1000-9999
mmonth, 1-12
dday of month, 1-31

◆ Date() [2/4]

mysqlpp::Date::Date ( const char *  str)
inlineexplicit

Initialize object from a C string containing a date.

String must be in the YYYY-MM-DD format. It doesn't have to be zero-padded.

◆ Date() [3/4]

template<class Str >
mysqlpp::Date::Date ( const Str &  str)
inlineexplicit

Initialize object from a C++ string containing a date.

This works with any stringish class that declares a c_str() member function: std::string, mysqlpp::String...

See also
Date(const char*)

◆ Date() [4/4]

mysqlpp::Date::Date ( time_t  t)
explicit

Initialize object from a time_t.

Naturally, we throw away the "time" part of the time_t. If you need to keep it, you want to use DateTime instead.

Member Function Documentation

◆ compare()

int mysqlpp::Date::compare ( const Date other) const
virtual

Compare this date to another.

Returns < 0 if this date is before the other, 0 of they are equal, and > 0 if this date is after the other.

Implements mysqlpp::Comparable< Date >.

◆ operator time_t()

mysqlpp::Date::operator time_t ( ) const

Convert to time_t.

The "time" part of the time_t is "now"

◆ year() [1/2]

unsigned short mysqlpp::Date::year ( ) const
inline

Get the date's year part.

There's no trickery here like in some date implementations where you have to add 1900 or something like that.

Referenced by mysqlpp::DateTime::convert().

◆ year() [2/2]

void mysqlpp::Date::year ( unsigned short  y)
inline

Change the date's year part.

Pass the year value normally; we don't optimize the value by subtracting 1900 like some other date implementations.


The documentation for this class was generated from the following files: