Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to have an automatic date in a table. Automatic date means I'd like to specify a start date which is shown in the first row of the table and every additional row shows appropriate next day.

I've already implemented a newcommand for the appropriate row. What I need now is a way to increase a specified date by a counter value.

Here are my commands:

\newcommand{\pweek}[3]{
    \setcounter{weekCounter}{1}
    \section*{Tagesberichte Woche #1}
    \begin{table}[h]
        \begin{tabular}{|p{1cm}|p{14cm}|}
            #2
        \end{tabular}
    \end{table}
    \newpage
    \section*{Wochenbericht #1}
#3
\newpage
}

\newcommand{\pday}[1]{
    \hline
    \arabic{weekCounter}\stepcounter{weekCounter} & #1 \\ \hline
}

I'd like to replace \arabic{weekCounter} with the corresponding date which has to be specified somehow in the parameter list of the command.

Do you know how to achieve this?

share|improve this question

migrated from stackoverflow.com Nov 12 '12 at 15:11

This question came from our site for professional and enthusiast programmers.

    
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 Nov 12 '12 at 15:15
add comment

1 Answer

up vote 4 down vote accepted

You can use advdate package to change current date, datenumber and datetime packages for date formatting.

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}

\usepackage{advdate}    % Advancing/saving dates
\usepackage{datetime}   % Dates formatting
\usepackage{datenumber} % Counters for dates

\newcommand{\pweek}[4]{
    \SaveDate    % Saves current date (advdate macro)
    \SetDate[#1] % Sets custom date   (advdate macro)
    \setdate{\the\year}{\the\month}{\the\day} % Saves custom date to 
                                              % predefined counter from datenumber
    \SetDate     % Restores current date (advdate macro)

    \section*{Tagesberichte Woche #2}
    \begin{table}[h]
        \begin{tabular}{|p{5cm}|p{5cm}|}
            #3
            \hline
        \end{tabular}
    \end{table}
    \newpage
    \section*{Wochenbericht #2}
    #4
    \newpage
}

\newcommand{\pday}[1]{
    \hline
    \twodigit{\thedateday}.\twodigit{\thedatemonth}.{\thedateyear} % Prints it in custom formatting
    %\datedate                                                     % For default format use \datedate
    \nextdate % Goes to the next day
    & #1 \\
}

\begin{document}

\pweek{30/10/2010}
{Hello}
{
\pday{One}
\pday{Two}
\pday{Three}
\pday{Four}
}
{Bye}

\end{document}

It shows:

enter image description here

share|improve this answer
    
After removing \AdvanceDate[-1] it's working like a charm. I don't actually see the reason to do that. Thanks anyway, @redmode! This has helped me a lot. –  SeveQ Nov 9 '12 at 18:35
    
\AdvanceDate[-1] helps starting with exactly the same date you pass to \pweek{}. If you remove this line first date in the table will be next to the date you passed (31.10.2010 in my example). If it is your intention - it's ok. –  redmode Nov 10 '12 at 10:36
    
For some reason I don't see yet it isn't doing that here. It starts with the given date without the \AdvanceDate[-1] instruction. If I add the instruction the first date is one day before the given date. Have you got a clue why? –  SeveQ Nov 10 '12 at 16:13
    
Well, I got the reason of the problem. It's leap year situation. Perhaps you were trying 2012 year - it's ok then. But with 2010, 2002, 1900, 2020 and other it gives a bias equal to the number of leap years between specified and current year. Also I found better solution - I'll edit my answer then. –  redmode Nov 10 '12 at 20:22
    
Yeah, I was trying 2012. Your new solution is again working like a charm. Thank you very much, redmode! –  SeveQ Nov 10 '12 at 22:30
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.