• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

How to get date string in source?

strutZ

Australian OT Member {AKA Beastn}
Joined
Nov 16, 2014
Messages
1,393
Solutions
7
Reaction score
552
Title proberly makes no sense... basically i am changing the player report bug function in tfs 1.2. i want it to get the date and insert it into my database.

Here is what i got.

Code:
void Game::playerReportBug(uint32_t playerId, const std::string& message, const Position position, uint8_t category)
{
    Database* db = Database::getInstance();
    std::ostringstream query;
    query << "INSERT INTO `reports` (`player`, `mappos`, `playerpos`, `comment`) VALUES (" << player->getName() << ',' << position << ',' << player->getPosition() << ',' << db->escapeString(comment) << ')';
    db->executeQuery(query.str());
}
 
Yeah, use the std library time, you need to add a column to the db if it doesnt have any date related and update it aswell.

Code:
#include <time.h> /* time_t, struct tm, difftime, time, mktime */
--
time_t date = time(NULL);
query << "INSERT INTO `reports` (`player`, `mappos`, `playerpos`, `comment` , `date`) VALUES (" << player->getName() << ',' << position << ',' << player->getPosition() << ',' << db->escapeString(comment) << ';'<< date<< ')';

Should work
 
Back
Top