On 10-Jul-15 12:50 AM, Christopher Pisz wrote:
> Does anyone by chance know how to get the difference between two
> datetimes expressed as a total number of weeks, using boost::posix_time?
>
>
> I am trying to calculate things like "is the current week a week, that
> meets the condition of, every 3rd week from 07/09/2015?"
>
> so i figure something like
> if( (currentdatetime - startdatetime).AsTotalWeeks() % 3 == 0)
I read "the difference between two datetimes expressed as a total number
of weeks" as "the difference between two datetimes, with the difference
expressed as a total number of weeks".
At the risk of stating the obvious, a week is always 7 days.
But you need general calendar functionality to find the number of days
between two dates. As of C++14 such calendar functionality is not
provided by the standard library. You can go with a DIY solution based
on the C library's [1]tm structure, which involves computing leap years
etc., see <url:
http://stackoverflow.com/questions/24403829/find-difference-between-two-dates-c>.
Or you can go with one of the two Boost calendar sub-libraries, or
perhaps platform specific functionality.
Cheers & hth.,
- Alf
Notes:
[1] tm can be converted to time_t e.g. via mktime, which can be
converted to std::chrono::whatever_clock via its from_time_t member
function. See Josuttis' "The C++ Standard Library: A Tutorial and
Reference" or the excerpt at <url: <url:
http://www.informit.com/articles/article.aspx?p=1881386&seqNum=2>.
--
Using Thunderbird as Usenet client, Eternal September as NNTP server.