# Day of year for date format Month/Day/Year

I want to know "day of year" for a calendar.

Here's an example:

Date format : Month/Day/Year = Day of year

• 3/19/2019 = 78

• 3/19/2020 = 79

How can I find/display the Day of the year?

• Please clarify in which way this posting may be related to TeX, LaTeX, and friends. – Mico Mar 8 '19 at 16:57

Let datenumber package do the job for you!

My code is more or less copied directly from the package documentation, see also here: Day of the year.

\documentclass{article}
\usepackage{datenumber}
\newcounter{dateone}\newcounter{datetwo}%
\newcommand{\julianday}{%
\setmydatenumber{datetwo}{\the\year}{\the\month}{\the\day}%
\setmydatenumber{dateone}{\the\year}{01}{01}%
\thedatetwo%
}
\newcommand{\juliandayof}[3]{%
\setmydatenumber{datetwo}{#1}{#2}{#3}%
\setmydatenumber{dateone}{#1}{01}{01}%
\thedatetwo%
}

\begin{document}

Today's Julian Day is \julianday.

The Julian Day of January, 1st, 2019 is \juliandayof{2019}{01}{01}.

The Julian Day of March, 19th, 2019 is \juliandayof{2019}{03}{19}.

The Julian Day of December, 31st, 2019 is \juliandayof{2019}{12}{31}.

The Julian Day of January, 1st, 2020 is \juliandayof{2020}{01}{01}.

The Julian Day of March, 19th, 2020 is \juliandayof{2020}{03}{19}.

The Julian Day of December, 31st, 2020 is \juliandayof{2020}{12}{31}.
\end{document}


With LuaTeX:

\documentclass[12pt]{article}
\usepackage{luacode}

\begin{document}
\luaexec{
reference = os.time{day=1, year=2020, month=1}
DaY = os.time{month=3, day=19, year=2020}
daysfrom = os.difftime(DaY, reference) / (24 * 60 * 60)
wholedays = math.floor(daysfrom+1)
s = "3 19 2020"
m,d,y = s:match("(\%S+)\%s+(\%S+)\%s+(\%S+)")
tex.print(m,"/",d,"/",y)
tex.print ("=")
tex.print(wholedays)
}
\end{document}