TransWikia.com

Iterate through dates

TeX - LaTeX Asked on February 5, 2021

I want to create a one day per page calendar. I create the pages in a for loop, but I don’t know how to save and increase it each iteration.

I thought about saving day, month and year separated, but then I would have to save how many days each month has and which years are leap years.

Is there a way to save a date and/or increase it?

2 Answers

There's an old package, that temporarily sets the date with AdvanceDate.

documentclass{article}

usepackage{pgffor}
usepackage{advdate}


begin{document}
ThisDay{0} % Set the day number to zero
ThisMonth{1} % Start in January
%ThisYear{2017} % for example
foreach x in {1,...,365} {%
  AdvanceDate[x]
  {hfillhugetextbf{today}hfill}  % Just as an example
  clearpage
}

end{document}

As can be seen from the screen shot the AdvanceDate command is aware of leap years

enter image description here

Answered by user31729 on February 5, 2021

Here is an answer using pgf macros, see Section 90 "Date and Calendar Utility Macros" of the manual:

documentclass{article}

usepackage{pgfcalendar}

begin{document}
pgfcalendar{cal}{2020-08-11}{2020-08-15}{%
  centeringhugebfseries%
  pgfcalendarshorthand wt,                         % weekdayname,
  pgfcalendarshorthand mt pgfcalendarcurrentday, % monthname dayofmonth,
  pgfcalendarcurrentyearclearpage%                % year
}
end{document}

The same, but using a shorthand as suggested by the manual:

documentclass{article}

usepackage{pgfcalendar}

begin{document}
let%=pgfcalendarshorthand
pgfcalendar{cal}{2020-08-11}{2020-08-15}{%
  centeringhugebfseries%
  %wt, %mt %d0, %y0clearpage%
}
end{document}

The first page looks like:

Preview of the first page, having the text "Tuesday, August 11, 2020" on it.

Answered by John on February 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP