# Wolfram Mathematica

## Convert to the Mayan Calendar

Identify the epoch (or start date) for the Mayan Long Count calendar as a Julian date.

In[1]:=
```epoch = JulianDate["Modified", DateObject[{-3114, 8, 11}, TimeZone -> 0]];```

Create a function to convert from Mayan Long Count calendar units to a Julian date.

In[2]:=
```JulianFromMayanLongCount[{baktun_, katun_, tun_, uinal_, kin_}] := epoch + 144000*baktun + 7200*katun + 360*tun + 20*uinal + kin```

FromJulianDate can be used to test an example input.

In[3]:=
`example = JulianFromMayanLongCount[{7, 17, 18, 19, 2}]`
Out[3]=
In[4]:=
`FromJulianDate["Modified", example, TimeZone -> 0]`
Out[4]=

Create a function to convert directly from Mayan Long Count to Gregorian date objects.

In[5]:=
```GregorianFromMayanLongCount[date_] := DateValue[ FromJulianDate["Modified", JulianFromMayanLongCount[date], TimeZone -> 0], "Day", DateObject]```
In[6]:=
`GregorianFromMayanLongCount[{7, 17, 18, 19, 2}]`
Out[6]=

Create a function to convert from a Julian date to Mayan Long Count calendar units.

In[7]:=
```JulianToMayanLongCount[date_] := NumberDecompose[ Floor[date - epoch], {144000, 7200, 360, 20, 1} ]```

JulianDate can be used to interpret any date input into a Julian date, which is then fed into JulianToMayanLongCount.

In[8]:=
```DateToMayanLongCount[date_] := Block[{\$TimeZone = 0}, JulianToMayanLongCount[JulianDate["Modified", date]] ]```

This function will now accept any input date and will return the corresponding Mayan Long Count calendar date list.

In[9]:=
`DateToMayanLongCount["May 4th, 2015"]`
Out[9]=
In[10]:=
`DateToMayanLongCount[AbsoluteTime[]]`
Out[10]=
In[11]:=
`DateToMayanLongCount[Today]`
Out[11]=

These two functions can be used to convert to and from the Long Count Mayan calendar.

In[12]:=
`DateToMayanLongCount[{1900, 1, 1}]`
Out[12]=
In[13]:=
```DateToMayanLongCount[{1900, 1, 1}]; GregorianFromMayanLongCount[%]```
Out[13]=