Can I get just the month and day from the RTC RV-8803 qwiic?

I’m starting a project where I want to have custom file names based on the date I pull from an RTC.

The examples all show how to set in already in the format MM-DD-YYYY but I’m interested in just using each part as part of a file name for the qwiic openlog. Ex. SEP28_21.txt for the file name.

I’m looking through the library but I’m not really sure what I’m looking at.

maybe?

uint8_t getMonth();

but I think that only updates the month and doesn’t have a string function?

getMonth() returns the current month as a number (1-12). You can use that with getYear() and getDate() to create the filename. You’ll also need an array of month names to index with getMonth()-1. Then you can format all that (try snprintf) into your filename.

Another option would be to create a struct tm from the RTC data and pass that to strftime(). Something like…

#include <time.h>
#include <SparkFun_RV8803.h>

RV8803 rtc;

void setup(void) {
    Serial.begin(115200);
    Serial.println("Starting...");
    Wire.begin();
    if (rtc.begin() == false) {
        Serial.println("RTC failed");
        while(1) ;
    }

    rtc.set24Hour();
    rtc.disableAllInterrupts();
    rtc.clearAllInterruptFlags();
}

#define FILE_NAME_MAX 20
void loop(void) {
    struct tm tm;
    char fname[FILE_NAME_MAX+1];
    rtc_get_tm(&tm);
    strftime(fname, FILE_NAME_MAX, "%b%d_%y.txt", &tm);
    Serial.println(fname);
    delay(5000);
}

void rtc_get_tm(struct tm *tm) {
    rtc.updateTime();
    tm->tm_isdst = -1;
    tm->tm_yday = 0;
    tm->tm_wday = 0;
    tm->tm_year = rtc.getYear() - 1900;
    tm->tm_mon = rtc.getMonth() - 1;
    tm->tm_mday = rtc.getDate();
    tm->tm_hour = rtc.getHours();
    tm->tm_min = rtc.getMinutes();
    tm->tm_sec = rtc.getSeconds();
}