Date as file name

Hello everyone!

I'm working on a datalogging project with Arduino Uno R3, and I wanted to know if there's a way to save files with the date and time, so it would create different files, anyone could give me any pointers on this? Thank you for reading!

If you want a date you need an RTC (Real Time Clock). This shield has all you need - Data-Logger Shield for Arduino - including some examples and tutorial.

Thanks, I'll check the tutorial, right now I'm using a chronodot, maybe there's something useful in the link.

Try this with a DS1307

// This isĀ  17 396

#include <SD.h>
#include "RTClib.h"
#include <Wire.h>
#include <string.h>

char filename[] = "00000000.CSV";
File myFile;

void setup()
Wire.begin(); //Important for RTClib.h

if (! RTC.isrunning()) {

Serial.println("RTC is NOT running!");

Serial.print("Initializing SD card...");

pinMode(10, OUTPUT);

if (!SD.begin(4)) {
Serial.println("initialization failed!");
Serial.println("initialization done.");

void loop()


void getFileName(){

DateTime 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[2] = (now.year()/10)%10 + '0'; //To get 3rd digit from year()
filename[3] = now.year()%10 + '0'; //To get 4th digit from year()
filename[4] = now.month()/10 + '0'; //To get 1st digit from month()
filename[5] = now.month()%10 + '0'; //To get 2nd digit from month()
filename[6] = + '0'; //To get 1st digit from day()
filename[7] = + '0'; //To get 2nd digit from day()


void createFileName(){
myFile =, FILE_WRITE);