RTC not working correctly

Nothing is clear about what you are trying to do, I assume you have a DS1307 and recklessly assume you are using a normal arduino. If that is the case, and you are prepared to focus on the problem as stated, you might find the following useful.
http://bildr.org/2011/03/ds1307-arduino/
Note that it uses two separate programmes, and it works with DS3231 as well.