wrong time save in sd card while writing in it.

some times the time get stored like this => 165:165:85 . Why?

It will be because of a problem with the code that you have not posted.

It could also be a problem with the hardware that you have not shown nor described.

My Code:

#include “RTClib.h”

RTC_DS1307 rtc;

void setup()
{
if (! rtc.begin())
{
Serial.println(F(“Couldn’t find RTC”));
while (1);
}

if (! rtc.isrunning())
{
Serial.println(F(“RTC is NOT running!”));
}
rtc.adjust(DateTime(2017,07,25,12,02,00));
}

void loop()
{

DateTime now = rtc.now();
delay(150);

Serial.print(now.year(), DEC);
Serial.print(’/’);
Serial.print(now.month(), DEC);
Serial.print(’/’);
Serial.print(now.day(), DEC);
Serial.print(F(" ("));
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(F(") "));
Serial.print(now.hour(), DEC);
Serial.print(’:’);
Serial.print(now.minute(), DEC);
Serial.print(’:’);
Serial.print(now.second(), DEC);
}

My RTC module : DS1307 RTC

Does that program write to the SD card ?

this is the sd card part.

File dataFile=SD.open("CO_00.txt",FILE_WRITE);
if(dataFile)
{

dataFile.print(now.year(), DEC);
dataFile.print('/');
dataFile.print(now.month(), DEC);
dataFile.print('/');
dataFile.print(now.day(), DEC);
dataFile.print(F(" ("));
dataFile.print(daysOfTheWeek[now.dayOfTheWeek()]);
dataFile.print(F(") "));
dataFile.print(now.hour(), DEC);
dataFile.print(':');
dataFile.print(now.minute(), DEC);
dataFile.print(':');
dataFile.print(now.second(), DEC);
dataFile.print(dataString4);
dataFile.print(dataString2);
dataFile.println(q);
dataFile.close();

}
else
{
Serial.println(F("Couldn't access file"));
}

this is the sd card part.

That was not in the code that you posted originally nor do I see how it relates to it.

If you need help please read this before posting a programming question and follow the instructions about posting a programming question.