| Home | Libraries | People | FAQ | More

#### datetime

Type representing MySQL `DATETIME` and `TIMESTAMP` data types.

##### Synopsis

Defined in header `<boost/mysql/datetime.hpp>`

    class datetime;

##### Types

Name | Description
--- | ---
local_time_point | A `std::chrono::local_time` that can represent any valid datetime, with microsecond resolution.
time_point | A `std::chrono::time_point` that can represent any valid datetime, with microsecond resolution.

##### Member Functions

Name | Description
--- | ---
as_local_time_point | Converts `*this` into a local time point (checked access).
as_time_point | Converts `*this` into a `time_point` (checked access).
datetime [constructor] | Constructs a zero datetime. — Constructs a datetime from its individual components. — Constructs a datetime from a `time_point`. — Constructs a datetime from a `local_time_point`.
day | Retrieves the day component (1-based).
get_local_time_point | Converts `*this` into a `local_time_point` (unchecked access).
get_time_point | Converts `*this` into a `time_point` (unchecked access).
hour | Retrieves the hour component.
microsecond | Retrieves the microsecond component.
minute | Retrieves the minute component.
month | Retrieves the month component (1-based).
operator!= | Tests for inequality.
operator== | Tests for equality.
second | Retrieves the second component.
valid | Returns `true` if `*this` represents a valid `time_point`.
year | Retrieves the year component.

##### Static Member Functions

Name | Description
--- | ---
now | Returns the current system time as a datetime object.

##### Related Non-member Functions

Name | Description
--- | ---
operator<< | Streams a datetime.

##### Description

Represents a Gregorian date and time broken by its year, month, day, hour, minute, second and microsecond components, without a time zone.

This type is close to the protocol and should not be used as a vocabulary type. Instead, cast it to a `std::chrono::time_point` by calling `as_time_point`, `get_time_point`, `as_local_time_point` or `get_local_time_point`.

Datetimes retrieved from MySQL don't include any time zone information. Determining the time zone is left to the application. Thus, any time point obtained from this class should be interpreted as a local time in an unspecified time zone, like `std::chrono::local_time`. For compatibility with older compilers, `as_time_point` and `get_time_point` return `system_clock` time points. These should be interpreted as local times rather than UTC. Prefer using `as_local_time_point` or `get_local_time_point` if your compiler supports them, as they provide more accurate semantics.

As opposed to `time_point`, this type allows representing MySQL invalid and zero datetimes. These values are allowed by MySQL but don't represent real time points.

Note: using `std::chrono` time zone functionality under MSVC may cause memory leaks to be reported. See this issue for an explanation and this other issue for a workaround.

Convenience header `<boost/mysql.hpp>`