5

I have a boost::date object. When I call month() interface on the object it returns me the month the object is holding but in terms of a string. Is there a way I can get the number associated with the month? i.e

date mySampleDate = date_from_tm(tm_myDate) ;
cout<<mySampleDate.month() ; //Gives the output as May/Jun/Jul etc. I need 5/6/7 etc.

I need to get this without recoverting the boost object into tm structure. This would result in too many converstions and a possible performance hit for me.

Ricketyship
  • 644
  • 2
  • 7
  • 22

1 Answers1

7

cout<<mySampleDate.month().as_number(); is exactly what you want!

jfly
  • 7,715
  • 3
  • 35
  • 65
  • how is this implemented in boost? Is .month() returning some class that has method as_number()? – Behrooz Karjoo Jan 25 '17 at 19:27
  • 1
    @BehroozKarjoo Internally `boost::date` is a template class, one of its template parameter, `calendar` defines the policies for converting the the year-month-day. `month()` returns `calendar::month_type`. – jfly Jan 25 '17 at 22:17