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.

How can I specify a relative date and let LaTeX insert the resulting absolute one?

For example like this:

\somedatecommand{next thursday}

Which should result in:

Thursday, 20.10.2011



Great would be also babel support (e.g. for non-english documents).

share|improve this question
Please have a look at Date calculations and datetime and datenumber package conflict? –  Yiannis Lazarides Oct 16 '11 at 16:35
I agree with @YiannisLazarides, this should be solvable using Date calculations, i.e. use the advdate package. –  Martin Scharrer Oct 16 '11 at 16:37
@YiannisLazarides, @Martin Scharrer - I have checked out the documentation to advdate and datetime but I can't figure out how to solve this. Today + n days works great - but something like 'next thursday' is different, i.e. the output is the same until the next thursday ... :) –  maxschlepzig Oct 16 '11 at 18:19
Feel free to develop the package. Get today's date from system, parse input to \somedatecommand get day offset and provide the new date in the format required. Repeat same for all languages in babel or use the special date and time formats provided. First part is not that difficult and possibly can fit into a post below. –  Yiannis Lazarides Oct 16 '11 at 18:34
add comment

1 Answer

up vote 5 down vote accepted

You could use the datetime package to format the dates and quoting form the package documentation:

As from version 2.42, the datetime package is now compatible with babel, however you must load the datetime package after the babel package.

The harder part is determining the date to print. This can be achieved using \AdvanceDate[n] macro from the advdate package to advance the date by a specified number of days. Then it is just a matter of determining how many days we need to advance to get to "next day-of-week".

enter image description here

\usepackage{xstring}% Needed for \IfStrEqCase
\usepackage{datenumber}% Date formatting
\usepackage{advdate}% Needed for \AdvanceDate
\usepackage{pgf}% For math

\pgfmathsetcounter{dateOffset}{7-int(\the\value{datedayname})}% Initialize
    }[\PackageError{\SetDateOffsetForNext}{Do not know "#1" as day of week}{}]%

    \SetDateOffsetForNext{#1}% Determine date offset
    \AdvanceDate[\value{dateOffset}]% Advance to specified day
    \mydate\today% Print specified date
    \AdvanceDate[-\value{dateOffset}]% Restore current day
    is next #1\par% debug output

Today is \mydate\today\par
share|improve this answer
Awesome. I have to remember the \pgfmathsetcounter command. –  maxschlepzig Oct 20 '11 at 8:27
add comment

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.