you would have to initialize the variables before creating your sd card file. As they are global, they would be used by the call back. You can create a function updateVariablesForTimeStamp() that you would call before creating files.
Assuming you use a DS3231, that's the way to read the 6 values
#include <RTClib.h> // https://github.com/adafruit/RTClib
RTC_DS3231 rtc;
unsigned int year = 2019;
byte month = 11;
byte day = 15;
byte hour = 15;
byte minute = 45;
byte second = 22;
// CALL THIS FUNCTION BEFORE DOING FILE OPERATIONS
void updateVariablesForTimeStamp()
{
DateTime now = rtc.now();
// HERE IS THE DATA YOU NEED TO UPDATE BEFORE THE dateTime Callback is called
year = now.year();
month = now.month();
day = now.day();
second = now.second();
minute = now.minute();
hour = now.hour();
}
void setup() {
Serial.begin(115200);
if (! rtc.begin()) {
Serial.println(F("NO RTC"));
while (1);
}
if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Need to initialize RTC, we use the last compile time of this sketch
}
void loop() {
}
(typed here, totally untested)