In this example we will discuss how to represent Date as an object in c++ using Boost Library.

C++ – Boost Library provides a type to represent date in Georgian Calendar i.e.

Representing a Date with boost::gregorian::date type

Let’s see how to create a Date Object and initialize it with a date 21’s March 2016 i.e.

Accessing day, month & year from a date object

Access day of month using day() member function i.e.

Access month using month() member function i.e.

Access year using year() member function i.e.

Access day of weak using year() member function i.e.

Let’s see a complete example,


Initializing Date object with Current Date

Let’s see how to initialize a date object with todays date instead of hard coded dates i.e.

Initializing Date object with current Date in Local Timezone,

Initializing Date object with current Date in UTC Timezone,

Checkout the example as follows,


My System is in Anchorage Time Zone where Date is 21st October at this point of time, therefore according to UTC Timezone Date is 22nd October.

To compile the above examples use following command in linux,

g++ –std=c++11 example.cpp -lboost_date_time

Python Recommendations:

C++ & C++11 Recommendations:

If you didn't find what you were looking, then do suggest us in the comments below. We will be more than happy to add that.

Subscribe with us to join 1500+ Python & C++ developers, to get more Tips &  Tutorials like this.