Dargor66
Dargor66

Reputation: 33

Boost Date going back in time

Hello I would like to go back in time using boost::Date_time. For example set the date to the one from 10 days ago. I tried using day_iterator but with no luck so far. Here is My attempt:

boost::gregorian::date dateGenerator(int howManyDays)
{
    boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();

    boost::gregorian::date date(now.date());
    boost::gregorian::day_iterator dayIterator(data,-1);

    for (; howManyDays != 0; ++dayIterator)
    {
        howManyDays--;
    }
    return date;

}

Thanks for help

Upvotes: 0

Views: 207

Answers (1)

Panagiotis Kanavos
Panagiotis Kanavos

Reputation: 131384

You can subtract a date duration from a date by using the - operator:

date_duration dd(howManyDays);
date d2 = date - dd;
return d2;

Upvotes: 1

Related Questions