Next Wednesday's date

Use the datenumber and etoolbox packages for counting and checking, respectively.

\documentclass{article}

\usepackage{datenumber,etoolbox}

\newbool{weddate}
\ifnumcomp{\arabic{datedayname}}{=}{3}{\setbool{weddate}{true}}{\setbool{weddate}{false}}

\newcommand\nextwed{%
  \unlessboolexpr{bool {weddate} }{%
    \addtocounter{datenumber}{1}%
    \setdatebynumber{\arabic{datenumber}}%
    \ifnumcomp{\arabic{datedayname}}{=}{3}{\setbool{weddate}{true}}{\setbool{weddate}{false}}%
  }%
  \datedate\setbool{weddate}{false}%
}

\begin{document}

\noindent
Next Wednesday is \nextwed. \\
The Wednesday after that is \nextwed.\\
Then we come to \nextwed.

\end{document}

Note this does not change the \today command, that will still give you today. The above code gives the following result:

enter image description here

Using \datedate after each \nextwed call will print the same date over and over. The \ifnumcomp check in the preamble is necessary in case today is Wednesday (in that case \nextwed does nothing, just prints the date).

Awesome that you're preparing before your class! :)


Here is a solution using the datetime2 package and expl3. The \badroit_find_next_date_for_dow:nnn function is fairly general: it allows one to find the next (Monday or Tuesday or ... as indicated by the second argument) starting from the date specified in the first argument and stores the resulting date in the third argument—in a form that functions from datetime2 can conveniently use.

\documentclass{article}
\usepackage[english]{babel}
% Use option 'showdow' to have the day of week printed by default
\usepackage[calc,en-GB]{datetime2}
\usepackage{xparse}

\ExplSyntaxOn

\newcount \badroit_tmp_count

% #1: <name> (in the sense of datetime2) of the start date
% #2: number of days (offset)
% #3: <name> (in the sense of datetime2) used to store the resulting date
\cs_new_protected:Npn \badroit_compute_offset_date:nnn #1#2#3
  {
    \DTMsaveddateoffsettojulianday {#1} {#2} { \badroit_tmp_count }
    \DTMsavejulianday {#3} { \number \badroit_tmp_count }
  }

\cs_generate_variant:Nn \badroit_compute_offset_date:nnn { nx }

% #1: <name> of the start date
% #2: which day to look for (0 for Monday, 1 for Tuesday, etc.)
% #3: <name> where the computed date is to be saved
\cs_new_protected:Npn \badroit_find_next_date_for_dow:nnn #1#2#3
  {
    \badroit_compute_offset_date:nxn {#1}
      { \int_mod:nn { 7 + (#2) - \DTMfetchdow {#1} } { 7 } }
      {#3}
  }

% #1: which day to look for (0 for Monday, 1 for Tuesday, etc.)
\cs_new_protected:Npn \badroit_display_next_chosen_dow:n #1
  {
    \DTMsavenow { badroit_display_next_chosen_dow.today }
    \badroit_find_next_date_for_dow:nnn
      { badroit_display_next_chosen_dow.today }
      {#1}
      { badroit_display_next_chosen_dow.result }
    % Use \DTMusedate to have the printed day of week start in lowercase if
    % the language allows it (e.g., with \usepackage[french]{babel}).
    \DTMUsedate { badroit_display_next_chosen_dow.result }
  }

\NewDocumentCommand { \NextWednesday } { }
  {
    \badroit_display_next_chosen_dow:n { 2 } % 2 is the number for Wednesday
  }

\ExplSyntaxOff

\begin{document}

Next \DTMenglishweekdayname{2} is \NextWednesday.

\end{document}

Screenshot

Tags:

Date