\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"}}
% Kalenderwoche
% https://www.tondering.dk/claus/cal/week.php
\pgfmathdeclarefunction{CW}{3}{% CW(year, month, day)
\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}%
%\f + 1 ist die Tagesnummer des Jahres
\pgfmathtruncatemacro{\f}{#2<3 ?
#3-1+31*(\month-1) : #3+floor((153*(#2-3)+2)/5)+58+\s}%
%\pgfmathtruncatemacro{\f}{DayNo(\year,\month,\day)-1} % möglich
\pgfmathtruncatemacro{\g}{mod(\a+\b,7)}%
% \d ist die Tagesnamen-Nummer (0=Monday, 1=Tuesday, etc.)
\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
% Tagesnummer pgfmath
% https://www.tondering.dk/claus/cal/week.php
% https://texwelt.de/wissen/fragen/23485/
\pgfmathdeclarefunction{DayNo}{3}{% DayNo(year,month,day)
\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.