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

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

#include <datetime.h>

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

Public Member Functions

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

Static Public Member Functions

static DateTime now ()
 Factory to create an object instance that will convert to SQL "NOW()" on insertion into a query. More...
 

Additional Inherited Members

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

Detailed Description

C++ form of SQL's DATETIME type.

This object exists primarily for conversion purposes. You can initialize it in several different ways, and then convert the object to SQL string form, extract the individual y/m/d h:m:s values, convert it to C's time_t, etc.

Constructor & Destructor Documentation

◆ DateTime() [1/3]

mysqlpp::DateTime::DateTime ( unsigned short  y,
unsigned char  mon,
unsigned char  d,
unsigned char  h,
unsigned char  min,
unsigned char  s 
)
inline

Initialize object from discrete y/m/d h:m:s values.

Parameters
yyear, 1000-9999
monmonth, 1-12
dday of month, 1-31
hhour, 0-23
minminute, 0-59
ssecond, 0-59

◆ DateTime() [2/3]

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

Initialize object from a C string containing a SQL date-and-time string.

String must be in the HH:MM:SS format. It doesn't have to be zero-padded.

◆ DateTime() [3/3]

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

Initialize object from a C++ string containing a SQL date-and-time string.

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

See also
DateTime(const char*)

Member Function Documentation

◆ compare()

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

Compare this object to another.

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

Implements mysqlpp::Comparable< DateTime >.

◆ now()

static DateTime mysqlpp::DateTime::now ( )
inlinestatic

Factory to create an object instance that will convert to SQL "NOW()" on insertion into a query.

This is just syntactic sugar around the default ctor

◆ year() [1/2]

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

Get the date/time value's year part.

There's no trickery here like in some date/time implementations where you have to add 1900 or something like that. It simply returns the year in natural form, in the range 1000-9999.

◆ year() [2/2]

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

Change the date/time value's year part.

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


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