Converting Variable Types

I need some help understanding how to convert data types. I am using Adafruits RTClib to control a DS3231 RTC. I need to take the RTC data which is defined as
uint16_t year() const { return 2000U + yOff; }
and input it into a structure variable that is a int.
post.year = now.year;
I'm using Platformio and I get the following error:

src\main.cpp:104:23: error: cannot convert 'DateTime::year' from type 'uint16_t (DateTime::)() const {aka short unsigned int (DateTime::)() const}' to type 'int'
post.year = now.year;

How do I convert this variable without making any changes to Adafruit's RTClib class or the structure that defines post.year?

Maybe try

post.year = (int) now.year;

I tried that and I get the following error:

src\main.cpp:104:34: error: invalid use of member function (did you forget the '()' ?)
post.year = (int)now.year;

From the looks of it, year is a class method. Maybe try:

post.year = now.year();

Great catch!!!!

post.year = now.year();

Works and I have to say Thanks Much!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.