[odb-users] Working with Date / DateTime / Time column in database without boost

Boris Kolpackov boris at codesynthesis.com
Thu May 30 08:56:27 EDT 2013


Hi,

rkadeFR <contact at rkade.fr> writes:

> After some research, I found only answers for the boost library
> concerning working with a DateTime column in a database.

In addition to the Boost Date-Time library, you can also use the
Qt date-time types.


> I found interesting to open a thread in order to discuss to work
> with a DateTime column without any library (only standard library
> C++11).

You need some C++ type that represents the date-time values and
there is nothing like this yet in standard C++. Well, C++11 added
the chrono library but all it adds, as far as I can see, is the
std::time_t and std::tm aliases for the corresponding C structs.
These types are very basic and using them directly would be quite
painful. That's why most people prefer to use something like the
Boost Date-Time library. But I suppose we could add mapping for
std::time_t and std::tm if people would find it useful.

At the same time, if you have your own date-time type, then
it is fairly easy to map it to the corresponding database date-
time type. For more information on how to do this, see this
detailed guide (the "Simple Value Types" section):

http://www.codesynthesis.com/~boris/blog/2012/10/16/custom-cxx-to-database-type-mapping-in-odb/

Boris



More information about the odb-users mailing list