Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, a web toolkit designed to help citizens, conservation practitioners, municipal decision-makers, researchers, educators, and students advance knowledge and stewardship of fresh water. New to EnviroDIY? Start here
Tips & Pointers

DS3231 Real Time Clock (RTC) date conversion

Real Time Clock (RTC) modules like the DS3231 chip (found on the ChronoDot and Seeeduino Stalker v2.3) keep track of the date and time for a datalogger circuit.  The module can output the number of seconds since January 1, 2000 as an integer, which can be very handy for recording a time stamp with your sensor data.  However, 1/1/2000 is not a common starting point for most epoch calculations.  They usually use what most people call Unix Time, which is the number of seconds since 1/1/1970.   So there can be issues if you’re trying to convert between DS3231 epoch time and Unix Time.  The simplest method is to add 946684800 seconds (the number of seconds between 1/1/1970 and 1/1/2000) to the DS3231 time to get Unix Time.

So:  DS3231Time + 946684800 = UnixTime

But there can also be an issue if you’re working with dates in MS Excel.  It considers 1/1/1900 as the starting point and expresses date as the number of days (not seconds)  since that starting point.  So if you want to convert and Excel dates to UnixTime, here’s the forumla:

(ExcelDate – 25569) * 86400 = UnixTime

And as shown above:   UnixTime – 946684800 = DS3231Time

3 Comments

  1. How do I convince a DS3231 to output seconds since 1/1/2000? I can’t find anything in the DS3231 data sheet describing such a function.

    • If you’re using the DS3231 library, you can use the following code:

      DateTime now = RTC.now(); //get the current date-time
      currentepochtime = (now.get()); //seconds since 1/1/2000

      Look at the “now” example that comes with the DS3231 library to see the whole sketch.

Leave a Reply