Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Boost C++ Compare Date's

    namespace pt = boost::posix_time;
    pt::ptime now = pt::second_clock::local_time();
    std::stringstream ss;
    ss << static_cast<int>(now.date().year()) << now.date().month().as_number() << now.date().day() << now.time_of_day().hours() << now.time_of_day().minutes();

i use the following code to get the current date and time. i store this in a database and grab it later again as a string. "201811272262" how would i compare the both of them so i know how many days are between?

my goal is to compare 2 date's and check if there 7 days or more between.


this is what i tried my self before

    const std::string cell = "201408151012";
const std::locale loc = std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y%m%d%H%M"));
std::istringstream is(cell);
is.imbue(loc);

boost::posix_time::ptime t;
is >> t;

const std::string cell2 = "201809191517";
const std::locale loc2 = std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y%m%d%H%M"));
std::istringstream is2(cell2);
is2.imbue(loc2);

boost::posix_time::ptime t2;
is2 >> t2;




boost::posix_time::time_duration td = t2 - t;

Log::GetLog()->info(boost::posix_time::to_simple_string(td));

Comments