Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8033223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:37:46+00:00 2026-06-05T01:37:46+00:00

I am using the boost libs and would just work with an int :

  • 0

I am using the boost libs and would just work with an int :

but I am receiving the error :

cannot convert »boost::gregorian::date_duration« to »int

What could I do ? Please help, I just want to check if my date passed the current date..
I get the right answer but could not work with. (range.length())

#include <iostream>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <ctime>
#include <fstream>

namespace bdt = boost::gregorian;
using namespace std;

int main(void)
{

time_t now = time(0);
tm *ltm = localtime(&now);

//Aktuelles Datum
    int y = 1900 + ltm->tm_year;
    int d = ltm->tm_mday;
    int m = 1 + ltm->tm_mon;
    bdt::date today(bdt::date(y, m, d));


//Ziel                               y   m   d  
    bdt::date electionDay(bdt::date(2012, 6, 6));
    bdt::date_period range(today, electionDay);


    std::cout  << range.length() << std::endl;
            int z = range.length() ;  



    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:37:48+00:00Added an answer on June 5, 2026 at 1:37 am

    Assuming you want the integer to represent the number of days in the period, then:

    range.length().days()
    

    Or, if you want to compare dates, you can do that without converting to periods, durations, integers, or anything else:

    if (today > electionDay) {
        std::cout << "Election day is in the past\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using boost::program_options and it suffers from the same as many other c++ libs,
I'm using boost::asio, and I have code like this: void CServer::Start(int port) { tcp::acceptor
I have just started with using boost libraries. For one of our projects i
I'm trying to compile using a compiled Boost libs. I can compile using header-only
I have this: using namespace boost::numeric::ublas; matrix<double> m (3, 2); int k = 0;
I'm just trying to compile the hello world example of boost.python WITHOUT using all
I'm just getting started with Boost for the first time, details: I'm using Visual
I recently downloaded http://boost-log.sourceforge.net/libs/log/doc/html/index.html but I can't seem to find out how to build
I'm trying to implement a Tribool type using http://www.boost.org/doc/libs/1_41_0/doc/html/tribool.html as reference. I'm using a
I've started using boost and Qt recently. I would like to know if all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.