Search code examples
boost-date-time

How to initialize a Boost date?


The page

http://www.boost.org/doc/libs/1_42_0/doc/html/date_time/gregorian.html#date_construction

explains that you can initialize a Boost date with this kind of call:

date d(2002, Jan, 10);

But when I try that, the compiler doesn't know 'Jan'.

It does work with:

date d(2002, 1, 10);

EDIT:

#include <boost/date_time/gregorian/gregorian.hpp>
..
{
    using namespace boost::gregorian;

    date limit_date(2010,Apr,1);
    date fake_date(2010,2,1);

    if (fake_date>limit_date)
    {
        ...
    }
}

Solution

  • Maybe you missed including of needed namespace? I can't say which one exactly, because you didn't post whole code, but I can suppose, that it can be something like:

    using namespace boost::gregorian;
    

    or

    using namespace boost::date_time;
    

    Update:

    Defenition of Jan:

    namespace boost {
    namespace date_time {
    
      //! An enumeration of weekday names
      enum weekdays {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
    
      //! Simple enum to allow for nice programming with Jan, Feb, etc
      enum months_of_year {Jan=1,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,NotAMonth,NumMonths};
    
    } } //namespace date_time