6

I want to make a table where I describe every week some facts, in two specific days. These days are fixed in the table, but they are selected arbitrarily. I would like to print the dates of each date automatically.

In the next MWE almost make all the work, but it only works for \today, I don't know how how change the start date, something like \setstartdate{}.

This code implies some calculations with dates, so I took some code from

Insert relative date and time specifications?

but there are some problems with the algorithm.

How can I fix the problem? or how can I improve it with another code?

This is the MWE

\documentclass{article}
\usepackage{xstring,datenumber,advdate,datetime,pgf,calc}
\usepackage{longtable}

\newcounter{dateOffset}%
\newcommand*{\SetDateOffsetForNext}[1]{%
\pgfmathsetcounter{dateOffset}{7-int(\the\value{datedayname})}% Initialize
\IfStrEqCase{#1}{%
    {mon}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+1,7))}}%
    {tue}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+2,7))}}%
    {wed}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+3,7))}}%
    {thu}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+4,7))}}%
    {fri}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+5,7))}}%
    {sat}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+6,7))}}%
    {sun}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+7,7))}}%
    }[\PackageError{\SetDateOffsetForNext}{Do not know "#1" as day of week}{}]%
    \IfEq{\the\value{dateOffset}}{0}{\pgfmathsetcounter{dateOffset}{0}}{}%
}%

\newcommand{\dayone}{mon}
\newcommand{\daytwo}{wed}

\newcounter{weeknumber}
\newcounter{sessionnumber}
\newcommand{\rowdayone}[1]{\addtocounter{weeknumber}{1}\addtocounter{sessionnumber}{1}%
\theweeknumber{} -- \thesessionnumber &
\SetDateOffsetForNext{\dayone}% Determine date offset
\addtocounter{dateOffset}{7*(\theweeknumber-1)}%
\AdvanceDate[\thedateOffset]% Advance to specified day
\today% Print specified date
%\AdvanceDate[-\thedateOffset]% Restore current day
& #1}
\newcommand{\rowdaytwo}[1]{\addtocounter{sessionnumber}{1}%
\theweeknumber{} -- \thesessionnumber &
\SetDateOffsetForNext{\daytwo}% Determine date offset
\addtocounter{dateOffset}{7*(\theweeknumber-1)}%
\AdvanceDate[\thedateOffset]% Advance to specified day
\today% Print specified date
%\AdvanceDate[-\thedateOffset]% Restore current day
& #1}

\newdateformat{short}{%
    \twodigit{\THEDAY}/\twodigit{\THEMONTH}%
    }


\begin{document}\short

%\SetDate[11/01/2015]

\begin{longtable}{|c|c|c|}
\rowdayone{description day 1 of week 1} \\
\rowdaytwo{description day 2 of week 1} \\
\rowdayone{description day 1 of week 2} \\
\rowdaytwo{description day 2 of week 2} \\
\rowdayone{description day 1 of week 3}
\end{longtable}

Last update \today

\end{document}

1 Answer 1

7

Since you are using both the datenumber and the advdate packages, you have to set the date for both these packages.

For example, to specify a date corresponding to November, 3rd, 1995, you have to issue

\setdatenumber{1995}{11}{03}

for the datenumber package, and

\SetDate[03/11/1995]

for the advdate package.

MWE:

\documentclass{article}
\usepackage{xstring,datenumber,advdate,datetime,pgf,calc}
\usepackage{longtable}

\newcounter{dateOffset}%
\newcommand*{\SetDateOffsetForNext}[1]{%
\pgfmathsetcounter{dateOffset}{7-int(\the\value{datedayname})}% Initialize
\IfStrEqCase{#1}{%
    {mon}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+1,7))}}%
    {tue}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+2,7))}}%
    {wed}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+3,7))}}%
    {thu}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+4,7))}}%
    {fri}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+5,7))}}%
    {sat}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+6,7))}}%
    {sun}{\pgfmathsetcounter{dateOffset}{int(mod(\the\value{dateOffset}+7,7))}}%
    }[\PackageError{\SetDateOffsetForNext}{Do not know "#1" as day of week}{}]%
    \IfEq{\the\value{dateOffset}}{0}{\pgfmathsetcounter{dateOffset}{0}}{}%
}%

\newcommand{\dayone}{mon}
\newcommand{\daytwo}{wed}

\newcounter{weeknumber}
\newcounter{sessionnumber}
\newcommand{\rowdayone}[1]{\addtocounter{weeknumber}{1}\addtocounter{sessionnumber}{1}%
\theweeknumber{} -- \thesessionnumber &
\SetDateOffsetForNext{\dayone}% Determine date offset
\addtocounter{dateOffset}{7*(\theweeknumber-1)}%
\AdvanceDate[\thedateOffset]% Advance to specified day
\today% Print specified date
%\AdvanceDate[-\thedateOffset]% Restore current day
& #1}
\newcommand{\rowdaytwo}[1]{\addtocounter{sessionnumber}{1}%
\theweeknumber{} -- \thesessionnumber &
\SetDateOffsetForNext{\daytwo}% Determine date offset
\addtocounter{dateOffset}{7*(\theweeknumber-1)}%
\AdvanceDate[\thedateOffset]% Advance to specified day
\today% Print specified date
%\AdvanceDate[-\thedateOffset]% Restore current day
& #1}

\newdateformat{short}{%
    \twodigit{\THEDAY}/\twodigit{\THEMONTH}%
    }


\begin{document}\short

\setdatenumber{1995}{11}{03}
\SetDate[03/11/1995]

\begin{longtable}{|c|c|c|}
\rowdayone{description day 1 of week 1} \\
\rowdaytwo{description day 2 of week 1} \\
\rowdayone{description day 1 of week 2} \\
\rowdaytwo{description day 2 of week 2} \\
\rowdayone{description day 1 of week 3}
\end{longtable}

Last update \today

\end{document} 

Output:

enter image description here

2
  • There is a mistake, the first monday after November, 3rd, 1995 is not 12/01 (January 12), but 06/11 (November 6). The idea is to print all the mondays (or other day) after the start day, choose with \setstartdate{}.
    – Gitano
    Jan 9, 2015 at 16:00
  • @Gitano Now I see. See the updated answer. Jan 9, 2015 at 17:05

You must log in to answer this question.

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