MySQL++ Reference Manual

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

# mysqlpp::Date Class Reference

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

`#include <datetime.h>`

Inheritance diagram for mysqlpp::Date:

[legend]
Collaboration diagram for mysqlpp::Date:

[legend]
List of all members.

## Public Member Functions
| Date ()
| Default constructor.
| Date (unsigned short y, unsigned char m, unsigned char d)
| Initialize object.
| 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.
template<class Str>
| Date (const Str &str)
| Initialize object from a C++ string containing a date.
| Date (time_t t)
| Initialize object from a `time_t`.
int | compare (const Date &other) const
| Compare this date to another.
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.
std::string | str () const
| Return our value in std::string form.
unsigned short | year () const
| Get the date's year part.
void | year (unsigned short y)
| Change the date's year part.

## 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

mysqlpp::Date::Date | ( | unsigned short | y,
|  | unsigned char | m,
|  | unsigned char | d |
| ) |  |  | `[inline]`

Initialize object.

Parameters:

  | y | year, 1000-9999
  | m | month, 1-12
  | d | day of month, 1-31

mysqlpp::Date::Date | ( | const char * | str | ) | `[inline, explicit]`

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.

template<class Str>

mysqlpp::Date::Date | ( | const Str & | str | ) | `[inline, explicit]`

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*)

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

int mysqlpp::Date::compare | ( | const Date & | other | ) | const

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.

mysqlpp::Date::operator time_t | ( |  | ) | const

Convert to time_t.

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

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.

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.

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

- datetime.h
- datetime.cpp