# Wolfram Mathematica

## Convert to the Mayan Calendar

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

In:= ```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:= ```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:= `example = JulianFromMayanLongCount[{7, 17, 18, 19, 2}]`
Out= In:= `FromJulianDate["Modified", example, TimeZone -> 0]`
Out= Create a function to convert directly from Mayan Long Count to Gregorian date objects.

In:= ```GregorianFromMayanLongCount[date_] := DateValue[ FromJulianDate["Modified", JulianFromMayanLongCount[date], TimeZone -> 0], "Day", DateObject]```
In:= `GregorianFromMayanLongCount[{7, 17, 18, 19, 2}]`
Out= Create a function to convert from a Julian date to Mayan Long Count calendar units.

In:= ```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:= ```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:= `DateToMayanLongCount["May 4th, 2015"]`
Out= In:= `DateToMayanLongCount[AbsoluteTime[]]`
Out= In:= `DateToMayanLongCount[Today]`
Out= These two functions can be used to convert to and from the Long Count Mayan calendar.

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