3

I am creating my own calendar. That means for each page in my book a day is reserved: dd.mm.yyy (day of week).

Via a foreach loop I change the current date:

\usepackage{advdate}
\usepackage{datetime} 



\foreach \days in {1, 3, 5, ..., 365} 
{
\AdvanceDate[\days]
...
     \AdvanceDate[\days].
     \DrawDateLeftSite{\today}
    \DrawDateRightSite{\AdvanceDate[1]\today}
.....
}

I now want to find out if a date is a weekend. If this is the case, I want to write the weekend on a page: dd.mm.yyy / dd.mm.yyy (Saturday / Sunday)

\usepackage{advdate}
\usepackage{datetime} 


\foreach \days in {1, 3, 5, ..., 365} 
{
...
     \AdvanceDate[\days].

    % if(weekend)
    % DrawWeekend{\today, \AdvanceDate[1]\today}

     \DrawDateLeftSite{\today}
    \DrawDateRightSite{\AdvanceDate[1]\today}
.....
}

I hope you can help me and thank you in advance.

1 Answer 1

1

I don't know about datetime but this test is certainly doable with pgfcalendar without advdate, for this you just add \days to the current date \year-\month-\day and test that date for weekend.

As a side effect, the weekday of that day is available in \pgfcalendarifdateweekday.

Code

\documentclass{article}
\usepackage{pgffor, pgfcalendar}
\begin{document}
\foreach \days in {1, 3, 5, ..., 365}{%
  \days\ days after \today\ is%
  \pgfcalendarifdate
    {\year-\month-\day+\days}
    {weekend}
    {}
    { \textbf{not}}
  a weekend because it's a
  \pgfcalendarweekdayname{\pgfcalendarifdateweekday}.
  \par}
\end{document}

Output

enter image description here

2
  • Just like what I've seen in other places, you put a % at the end of a line. Why do so?
    – youthdoo
    Dec 3, 2022 at 9:14
  • @youthdoo To suppress a space from appearing in my text. The end of a line will be converted into a space (unless it won't). See for example Q7453 or its related questions. You can check for yourself by removing or adding them at the end of the line and see how the output changes. Dec 3, 2022 at 11:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .