\documentclass[margin=5mm, varwidth]{standalone}
\usepackage{tikz}
\begin{document}
\pgfmathtruncatemacro{\year}{2018}
\pgfmathtruncatemacro{\month}{10}
\pgfmathtruncatemacro{\day}{31}
\newcommand\Date{\year-\month-\day}
\def\Weekdayname{{"Montag","Dienstag","Mittwoch",
"Donnerstag","Freitag","Samstag","Sonntag"}}
\pgfmathdeclarefunction{CW}{3}{
\pgfmathtruncatemacro{\a}{#2<3 ? #1-1 : #1}
\pgfmathtruncatemacro{\b}{floor(\a/4)-floor(\a/100)+floor(\a/400)}
\pgfmathtruncatemacro{\c}{floor((\a-1)/4)-floor((\a-1)/100)+floor((\a-1)/400)}
\pgfmathtruncatemacro{\s}{\b-\c}
\pgfmathtruncatemacro{\e}{#2<3 ? 0 : \s+1}
\pgfmathtruncatemacro{\f}{#2<3 ?
#3-1+31*(\month-1) : #3+floor((153*(#2-3)+2)/5)+58+\s}
\pgfmathtruncatemacro{\g}{mod(\a+\b,7)}
\pgfmathtruncatemacro{\d}{mod(\f+\g-\e,7)}
\pgfmathtruncatemacro{\n}{\f+3-\d}
\pgfmathtruncatemacro{\CW}{\n<0 ? 53-floor((\g-\s)/5) : (
\n>(364+\s) ? 1 : floor(\n/7)+1)}
\pgfmathparse{int(\CW)}
}
\Date $~\Rightarrow~$ \pgfmathparse{CW(\year,\month,\day)}Kalenderwoche \pgfmathresult
\pgfmathdeclarefunction{DayNo}{3}{
\pgfmathtruncatemacro{\a}{#2<3 ? #1-1 : #1}
\pgfmathtruncatemacro{\b}{floor(\a/4)-floor(\a/100)+floor(\a/400)}
\pgfmathtruncatemacro{\c}{floor((\a-1)/4)-floor((\a-1)/100)+floor((\a-1)/400)}
Was spricht gegen ein einfaches
\newcommand
? Übrigens habe ich glaube ich anderswo schon erwähnt, dass man Makronamen mit nur einem Buchstaben vermeiden sollte, da diese für die ganzen Akzente reserviert sind (\b
,\c
,\d
) und dass man\day
,\month
und\year
nicht überschreiben sollte, weil sonst das Datum im Rest des Dokuments nicht mehr stimmt.