39

I'm building a LaTeX document that helps me to formulate quotations for my customers. Since I decided to offer monthly recurring payments I'd like to have payment dates calculated automatically starting from a specific one. Say, for example, that you have:

\today{}

then I need to have:

  • \today +30 days
  • \today +60 days
  • \today +180 days

and so on...

Is that possible?

EDIT: I ended up using the package advdate because I obtained a more compact result to do this:

% Payment starts in 4 months.
\AdvMonth{4}

% 1 chunk per month -> due date:
\begin{enumerate*}
    \AdvMonth{1} \item due date: \textbf{\today}
        ...
\end{enumerate*}

3 Answers 3

25

See the advdate package.

Edit Six years later, I am finally getting around to adding an example. It does what the package says it does.

\AdvanceDate Advances date the specified number of days [an argument in square brackets, defaulting to 1] and sets the result to \today

Two things to notice there:

  • To advance by 30 days, for instance, the syntax is \AdvanceDate[30].

  • The package effectively uses \today as a variable. Which means if you are recording several dates relative to today, you need to advance incrementally. If you want 30 days, then 60 days, you need to call \AdvanceDate[30] twice.

  • Of course, TeX's scoping rules are still in effect. So if you advance \today in a group, the changes end when the group ends. So if you make a table your increments are forgotten at the end of each cell.

Here is an example document, showing both of these:

\documentclass{article}
\usepackage{advdate}
\begin{document}
Today is: \today

Tomorrow is: \DayAfter

30 days from today is \AdvanceDate[30]\today.

60 days from today is \AdvanceDate[30]\today.

180 days from today is \AdvanceDate[120]\today.
\AdvanceDate[-180]
\bigskip

\begin{tabular}{|cc|}\hline
    Relative description & Date \\\hline
    today & \today \\
    tomorrow & \DayAfter \\
    30 days from today & \AdvanceDate[30]\today\\
    60 days from today & \AdvanceDate[60]\today\\
    180 days from today & \AdvanceDate[180]\today\\\hline
\end{tabular}
\end{document}

mwe output

1
  • 13
    This answer would benefit from an example. Commented Oct 16, 2011 at 16:37
24

This is possible with the datenumber package

\documentclass{article}
\usepackage{datenumber}

\begin{document}

\setdatetoday
\addtocounter{datenumber}{30}%
\setdatebynumber{\thedatenumber}%
In 30 days is \datedate

\setdatetoday
\addtocounter{datenumber}{60}%
\setdatebynumber{\thedatenumber}%
In 60 days is \datedate

\setdatetoday
\addtocounter{datenumber}{90}%
\setdatebynumber{\thedatenumber}%
In 90 days is \datedate

\end{document}

Which results in:

enter image description here

2
  • +1 But I still need that the first date is parametric, not just from today.
    – microspino
    Commented Nov 3, 2010 at 15:50
  • 6
    @microspino, if you run texdoc datenumber on a command line, you'll find out about a command \setdatenumber to start from arbitrary dates. Commented Nov 3, 2010 at 16:03
10

This is possible with the datetime2 package:

\documentclass[italian]{article}
\usepackage[calc,useregional]{datetime2}
\newcount\myct
\newcount\datecount
\newcommand{\myday}[1]{%
    \DTMsavenow{mydate}
    \DTMsaveddateoffsettojulianday{mydate}{#1}{\myct}
    \DTMsavejulianday{mydate}{\number\myct}
    \DTMusedate{mydate}
}

\begin{document}

\today~ is the day

In 10 days is  \myday{10}

In 30 days is  \myday{30}

In 90 days is  \myday{90}


\end{document}
1
  • 1
    Thank you! Exactly what I was looking for. The only answer that does not use the old datetime and advdate packages.
    – Ben
    Commented Apr 19, 2018 at 17:47

You must log in to answer this question.

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