Writing RTC time to SD card help

I would like to write the time and maybe the date to my SD card everything compiles fine the the data is wrong.
here is the code:

res=file.openFile("LogData.TXT", FILEMODE_TEXT_WRITE);
    file.openFile("LogData.TXT", FILEMODE_TEXT_WRITE);
    if (res==NO_ERROR)
    {
      // RTC Time Function
      DateTime now = RTC.now(); 
      
      
    varHour = (now.Hour(), DEC);
    char varHourChar[60];
    String varHourStr;
    
    varHourStr=String(varHour); //converting integer into a string
    varHourStr.toCharArray(varHourChar,60); //passing the value of the string to the character array
    Serial.print("Min is:");
    Serial.println(varHourChar);
     file.writeLn(varHourChar);
      Serial.print(varHourChar);
      //file.writeLn((now.minute(), DEC));
      file.closeFile();

what i get is "10" in the serial window and on the sd card

this is the code for all the date and time:

// Make a string for assembling the data to log:
      String dataString = "";
      char *dataStringChar; 
      // Assemble Strings to log data
      String theyear = String(now.year(), DEC);  //"integer" converting integer into a string
      String mon = String(now.month(), DEC);     //"integer" converting integer into a string
      String theday = String(now.day(), DEC);    //"integer" converting integer into a string
      String thehour = String(now.hour(), DEC);  //"integer" converting integer into a string
      String themin = String(now.minute(), DEC); //"integer" converting integer into a string
      //Put all the time and date strings into one String
      dataString = String ("LED On: " + theyear + "/" + mon + "/" + theday + ", " + thehour + ":" + themin + " | ");
      dataString.toCharArray(dataStringChar,60); // passing the value of the string to the character array
      // write the dataString to the microSD card
      file.writeLn(dataStringChar);
      Serial.print(dataString);

This does not work as well!
I would think that I could do something like this

      file.writeLn((now.minute(), DEC));

but that gets a error:

error: initializing argument 1 of 'uint16_t tinyFAT::writeLn(char*)'

Thanks for your help!!!

file.writeLn((now.minute(), DEC));

Something like that will probably work better if you convert the integer to ASCII with:

http://playground.arduino.cc/Code/PrintingNumbers

With:

itoa ((now.hour(), DEC), varHourChar, 30);  
          runWrite2("LogData.TXT", varHourChar);
          
          Serial.print(varHourChar);

I get "A" not the hour

The issue seems to be here: "file.writeLn(dataString);"

// Make a string for assembling the data to log:
      String dataString = "";
      char *dataStringChar; 
      // Assemble Strings to log data
      String theyear = String(now.year(), DEC);  //"integer" converting integer into a string
      String mon = String(now.month(), DEC);     //"integer" converting integer into a string
      String theday = String(now.day(), DEC);    //"integer" converting integer into a string
      String thehour = String(now.hour(), DEC);  //"integer" converting integer into a string
      String themin = String(now.minute(), DEC); //"integer" converting integer into a string
      //Put all the time and date strings into one String
      dataString = String ("LED OFF: " + theyear + "/" + mon + "/" + theday + ", " + thehour + ":" + themin + " | ");
      // write the dataString to the microSD card
      file.writeLn(dataString);

I get this error:

error: no matching function for call to 'tinyFAT::writeLn(String&)'
D:\Arduino\arduino-1.5.2\libraries\tinyFAT/tinyFAT.h:126: note: candidates are: uint16_t tinyFAT::writeLn(char*)

If I add this code to it

dataString.toCharArray(dataStringChar,120); // passing the value of the string to the character array
      file.writeLn(dataStringChar);

It will compile put I get "10" as the output

I think you need to use file.print.

This is a piece of code that time stamps from an RTC to an SD card for me.

DateTime now = RTC.now(); 

  myFile.print(now.year(), DEC);
  myFile.print(" , ");
  myFile.print(now.month(), DEC);
  myFile.print(" , ");
  myFile.print(now.day(), DEC);
  myFile.print(" , ");
  if (now.hour()<10)
    myFile.print("0");
  myFile.print(now.hour(), DEC);
  myFile.print(" , ");
  if (now.minute()<10)
    myFile.print("0");
  myFile.print(now.minute(), DEC);
  myFile.print(" , ");
  if (now.second()<10)
    myFile.print(" 0");
  myFile.print(now.second(), DEC);

I am using tinyFat which has no member "file.print."

      String theyear = String(now.year(), DEC);  //"integer" converting integer into a string
      String mon = String(now.month(), DEC);     //"integer" converting integer into a string
      String theday = String(now.day(), DEC);    //"integer" converting integer into a string
      String thehour = String(now.hour(), DEC);  //"integer" converting integer into a string
      String themin = String(now.minute(), DEC); //"integer" converting integer into a string

Creating a String object, and then invoking the copy constructor to copy it to a third String is just plain wasteful.

The DEC argument is the default. So, leave it off.

    String theYear = now.year();

etc.

      dataString = String ("LED OFF: " + theyear + "/" + mon + "/" + theday + ", " + thehour + ":" + themin + " | ");

Again, creating a String and then invoking the copy constructor is pissing away resources unnecessarily.

      dataString = "LED OFF: " + theyear + "/" + mon + "/" + theday + ", " + thehour + ":" + themin + " | ";

Then, you need to get the C string that the String instance wraps.

char realData[80];
dataString.toCharArray(realData, 80);

Then, you can use file.writeLn(realData); to store the data in the file.

Or, avoid the useless String class altogether, and use sprintf().