# advancedate and ifthenelse in latex

I am trying to write a course syllabus for a class that meets only certain days of the week (M, W). I want to check the day of the class and advance it by 2 days or 5 days depending on the day. The following code does not seem to work (fails at the \ifthenelse statement)

\documentclass{article}
\usepackage[ddmmyyyy]{datetime}
\usepackage{tikz}

\newdateformat{syldate}{\THEMONTH/\THEDAY%(\shortdayofweekname%{\THEDAY}{\THEMONTH}{\THEYEAR})}

\newcommand{\class}[1]{
\def \currday {\shortdayofweekname{\the\day}{\the\month}{\the\year}}
}

\SetDate[06/01/2014]

\begin{document}
\class{First Class}
\class{Second class}
\class{Class after holiday}

\end{document}


The reason I want to do this way, is because I want to check if the \today is in a list of holidays and if so automatically advance to the next class day. Any advice on how to do this? More efficient code is also appreciated.

• Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Dec 30 '13 at 20:57

Hopefully, this is what you're after:

\documentclass{article}
\usepackage[ddmmyyyy]{datetime}% http://ctan.org/pkg/datetime

\newdateformat{syldate}{\THEMONTH/\THEDAY/\THEYEAR}%(\shortdayofweekname%{\THEDAY}{\THEMONTH}{\THEYEAR})}

\newsavebox{\MONDAY}\savebox{\MONDAY}{Mon}% Mon

\makeatletter
\newcommand{\cleardate}[1]{%
\expandafter\let\csname date@#1@d\endcsname\relax% Clear day
\expandafter\let\csname date@#1@m\endcsname\relax% Clear month
\expandafter\let\csname date@#1@y\endcsname\relax% Clear year
}
\makeatother

\newcommand{\class}[1]{%
\cleardate{mydate}% Clear date
\newdate{mydate}{\the\day}{\the\month}{\the\year}% Store date
\setbox1=\hbox{\shortdayofweekname{\getdateday{mydate}}{\getdatemonth{mydate}}{\getdateyear{mydate}}}%
\ifdim\wd1=\wd\MONDAY
\else
\fi%
}

\SetDate[06/01/2014]

\begin{document}

\class{First class}
\class{Second class}
\class{Third class}
\class{Fourth class}
\class{Fifth class}
\class{Sixth class}
\class{Seventh class}

\end{document}


The process stores the date in mydate to join the interfaces of datetime and advdate. The comparison against the day-of-the-week is done by testing the width of the word Mon. Each three-letter/short-date has a different length:

• Great! thanks for the explanation. It is quite helpful. I have a follow up. I will ask it here. – Nikhil Dec 29 '13 at 12:54
• Follow up: I notice this is sensitive to the font. It doesn't work if I use the fourier font for instance (\usepackage{fourier}). How can I get around this? – invictus Sep 2 at 18:23
• @invictus: Rather use \AtBeginDocument{\savebox{\MONDAY}{Mon}} than setting \MONDAY within the preamble. – Werner Sep 2 at 20:40
• where exactly would that line go? before the declaration of \class? After? – invictus Sep 4 at 13:44
• @invictus: This MWE should make it clear. – Werner Sep 4 at 15:38