## The musings of a physician who has served the community for over six decades

Related Topics

Programming;GRF4
Program notes by GRF4

### Converting Mayan Dates

The Mayans had a number of date systems, the Long Count being the most satisfactory relative to the motion of the earth and sun.

In C++, here are the fundamental routines for converting back and forth.

The Julian Date Count functions can be found here: https://www.philadelphia-reflections.com/blog/1722.htm

```
void MayanToGregorian (int baktun, int katun, int tun, int uinal, int kin,
int& gregorianMonth, int& gregorianDay, int& gregorianYear)
{
// Convert a Mayan Long Count date into Gregorian

// 1. convert Mayan date into days from the Mayan 0 date ... the beginning of their calendar
// 2. convert Mayan days into a Julian Period Date
// 3. convert Julian Period Date into Gregorian MM DD YYYY

// 1. find the total number of Mayan days

long int totalMayanDays;

totalMayanDays = (baktun * 144000) + (katun * 7200) + (tun * 360) + (uinal * 20) + kin;

// 2. convert to Julian Period Date (per https://www.pauahtun.org/Calendar/longcount.html)

long int julianPeriodDate;
const long int correlationConstant = 584285;

julianPeriodDate = totalMayanDays + correlationConstant;

// 3. Convert the Julian Period Date number to Gregorian MM DD YYYY

JulianToGregorian (julianPeriodDate, gregorianMonth, gregorianDay, gregorianYear);

return;
}

void JulianToMayan (long int julianDateNumber,
int& baktun, int& katun, int& tun, int& uinal, int& kin)
{
// Convert a Julian Period Date number to Mayan Long Count date

const long int kinCount    = 1;		      // 1 kin                          = 1 day
const long int uinalCount  = 20 * kinCount;   // 1 uinal  = 20 kins             = 20 days
const long int tunCount    = 18 * uinalCount; // 1 tun    = 18 uinals = 18*20   = 360 days
const long int katunCount  = 20 * tunCount;   // 1 katun  = 20 tuns   = 20*360  = 7,200 days
const long int baktunCount = 20 * katunCount; // 1 baktun = 20 katuns = 20*7200 = 144,000 days

long int totalMayanDays;
const long int correlationConstant = 584285;

// reverse engineer the Mayan to Julian

totalMayanDays = (julianDateNumber - correlationConstant) + 1;

baktun = totalMayanDays / baktunCount;
totalMayanDays = totalMayanDays % baktunCount;

katun = totalMayanDays / katunCount;
totalMayanDays = totalMayanDays % katunCount;

tun = totalMayanDays / tunCount;
totalMayanDays = totalMayanDays % tunCount;

uinal = totalMayanDays / uinalCount;
totalMayanDays = totalMayanDays % uinalCount;

kin = totalMayanDays / kinCount;

return;
}
```

(my thanks to https://centricle.com/tools/html-entities/ for HTML encoding)

Originally published: Sunday, September 13, 2009; most-recently modified: Monday, June 04, 2012