[odb-users] How to handle date in C++ with ODB

Boris Kolpackov boris at codesynthesis.com
Thu Jul 21 09:43:47 EDT 2011


Bright Dadson <losintikfos at yahoo.co.uk> writes:

> Can anyone share light on how to convert MySQL date with C++ primitive
> via ODB. Can I convert long to date and persisted as bigint - any ideas?!

The best way would be to use either the Boost or Qt profile library.
They provide automatic mapping between boost::gregorian::date (in
case of Boost) or QDate (in case of Qt) and the MySQL DATE type.
See the 'boost' and 'qt' examples as well as the ODB manual for
more information.

Alternatively, you can map your own C++ date type to my MySQL DATE.
For more information on how to do this see the 'mapping' example.

Finally, you can convert your C++ date representation to some
integral type (e.g., as a number of days since some predefined
date) and store that in the database.


More information about the odb-users mailing list