Hi, I'm trying to get the current date in my filename. Now I found a piece of code which should do it, but that does not give the right output. It looks like I need some kind of conversion ?
My code is:
void getFileName(){
DateTime now = RTC.now();
//filename[0] = (now.year()/1000)%10 + '0'; //To get 1st digit from year()
//filename[1] = (now.year()/100)%10 + '0'; //To get 2nd digit from year()
filename[0] = (now.year()/10)%10 + '0'; //To get 3rd digit from year()
filename[1] = now.year()%10 + '0'; //To get 4th digit from year()
filename[2] = now.month()/10 + '0'; //To get 1st digit from month()
filename[3] = now.month()%10 + '0'; //To get 2nd digit from month()
filename[4] = now.day()/10 + '0'; //To get 1st digit from day()
filename[5] = now.day()%10 + '0'; //To get 2nd digit from day()
Serial.println (filename);
}
The output I'm getting is : 65@5@500.CSV
This doesn't make sense, while the date is 21/5/19, so I would expect 21051900. Does anyone no what goes wrong ?
please edit your post, select the code part and press the </> icon in the tool bar to mark it as code. It's unreadable as it stands. (also make sure you indented the code in the IDE before copying, that's done by pressing ctrlT on a PC or cmdT on a Mac)
It looks like your RTC is either not working or not being read correctly.
What kind of RTC do you have? How is it wired up? What RTC library (if any) are you using?
Please post your entire sketch.