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]
List of all members.

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.
 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.
template<class Str>
 DateTime (const Str &str)
 Initialize object from a C++ string containing a SQL date-and-time string.
 DateTime (time_t t)
 Initialize object from a time_t.
int compare (const DateTime &other) const
 Compare this object to another.
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.
void year (unsigned short y)
 Change the date/time value's year part.

Static Public Member Functions

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

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

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:
y year, 1000-9999
mon month, 1-12
d day of month, 1-31
h hour, 0-23
min minute, 0-59
s second, 0-59

mysqlpp::DateTime::DateTime ( const char *  str  )  [inline, explicit]

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.

template<class Str>
mysqlpp::DateTime::DateTime ( const Str &  str  )  [inline, explicit]

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

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

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.

static DateTime mysqlpp::DateTime::now (  )  [inline, static]

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

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.

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.


The documentation for this class was generated from the following files:
Generated on 20 Jun 2013 for MySQL++ by  doxygen 1.4.7