I want to calculate the beginning and ending date of a week (first day is Monday, last is Sunday). This is working fine for a single date. Now I want to calculate the start and end of multiple weeks consecutively in a loop, given the starting date (always a Monday) and the number of weeks to calculate. This works only for the first calculation, meaning that the date of the next Sunday is correct, but after that the date is always reset after each loop.
My algorithm to calculate the next date looks like this:
# cursor is at a Monday
for n in 1 .. 10:
print(cursor) # Monday
add 6 days to cursor
print(cursor) # Sunday
add 1 day to cursor
end for
Minimum Working Example:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[calc]{datetime2}
\usepackage{pgffor}
\setlength{\parindent}{0pt}
\begin{document}
\newcommand{\nweeks}{4}
\newcommand{\startdate}{2020-09-07}
\newcount\datecount
\newcommand{\dateoffset}[2]{%
\DTMsaveddateoffsettojulianday{#1}{#2}{\datecount}%
\DTMsavejulianday{#1}{\datecount}%
}
\DTMsavedate{currentdate}{\startdate}
Start-Week-1: \DTMusedate{currentdate}\
\dateoffset{currentdate}{6}
End-Week-1: \DTMusedate{currentdate}\
\dateoffset{currentdate}{1}
Start-Week-2: \DTMusedate{currentdate}\
\dateoffset{currentdate}{6}
End-Week-2: \DTMusedate{currentdate}\
\dateoffset{currentdate}{1}
\DTMsavedate{currentdate}{\startdate}
\foreach \n in {1,...,\nweeks}{
Start-Week-\n: \DTMusedate{currentdate}\
\dateoffset{currentdate}{6}
End-Week-\n: \DTMusedate{currentdate}\
\dateoffset{currentdate}{1}
}
\end{document}


You can't use macro parameter character # in horizontal mode.– ShadowEagle Sep 02 '20 at 18:59expl3package is very ancient. I don't see any#used in horizontal mode. Maybe you didn't copy the definition of\intstepinline? The first error would definitely be more informative than the last one. – frougon Sep 02 '20 at 19:42expl3 2017/05/29 L3 programming layerMaybe not ancient, but definitely not up to date. – ShadowEagle Sep 02 '20 at 20:38