SD Module - Writing timestamp to txt file & data from sensors

go3mon:
Thanks 4 support!

How can I change this function?

void timestamp(String) {

...
...
myTime = here I need to have this : "2017-10-28: 18:25"

}





I tink I cant do "myFile.println(timestamp())" in this way.

No, you indeed can't because the function does not return anything.

What is the function of String as a parameter to the function.

You can use something like below

char *timeStamp()
{
  int year = 2017;
  int month = 10;
  int day = 28;
  int hour = 18;
  int minute = 40;
  int second = 10;

  sprintf(buffer, "%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second);
  return buffer;
}

This will store the timestamp in a char buffer that is declared as a global variable. It also shows how to return the (pointer to) the buffer.

Net you can (example for setup)

// text buffer to hold yyyy-MM-dd HH:mm:ss
char buffer[20];

void setup()
{
  Serial.begin(9600);

  timeStamp();


  Serial.println(buffer);

  or

  Serial.println(timeStamp());

}

The first print prints the content of buffer; the second one basically does the same but by calling timestamp and using the returned pointer to the text. Note that if you use the latter three times, you might get different times if the time comes from the RTC as the seconds might have moved.