I have an SQL table with DATETIME field in it. I am using the table from C++. when I fill the row, I need to submit a date time. What is the simplest way to get this?
Using ubuntu and need it to work with Qt also, so better without adding external libraries like boost::.
I was in a similar situation once, so I wrote my own
DateTimeclass.On pastebin:
DateTime.h
DateTime.cpp
If you are using
MySQL Connector/C++, then I believe this library tries to emulateJDBCfrom Java. The classes from thejava.sqlpackage in Java are defined in thesqlnamespace in C++.JDBC has a
java.sql.Timestampclass, so the C++ library should have asql::Timestampclass.However, the MySQL 5.6 documentation shows that there are feature requests for MySQL Connector/C++ for them to add the
Date,TimeandTimestamptypes fromJDBCto the C++ library. So they may not be available yet.For now, the answers to this question suggest that you should use
std::stringfor fetching and settingTimestampfields.Insert:
Select:
If you wanted to manipulate these
Timestamps in your program. It would be trivial to use thesestd::stringobjects to createDateTimeobjects using the class that I attached onpastebin.If you aren’t too deep into
MySQL Connector/C++, you could consider switching toMySQL++. This library definitely has aDateTimetype.