GeneralIncrement Date

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
arobase
Posts: 33
Joined: Sat Apr 14, 2012 7:46 pm

Increment Date

Post by arobase »

Hi,

I'd like to be able to set a reference date and invoke it with an increment. I guess I will have to write a macro but I'm just not sure where to start.

Code: Select all


\documentclass{article}
\usepackage[english]{babel}

\usepackage{datetime}
%\usepackage{datenumber,fp}

\newdate{mydate}{01}{01}{1800} % reference date
\newcommand{\addyears}[1]{
	%\getdateyear{mydate} %and then what?
}

\begin{document}

Year \addyears{0} was the first day of the 19th century, duh! Five years later was \addyears{5}.	% 01/01/1805

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

Increment Date

Post by nlct »

Is this what you're looking for?

Code: Select all

\documentclass{article}
\usepackage[english]{babel}

\usepackage{datetime}
\usepackage{etoolbox}

\newdate{mydate}{01}{01}{1800} % reference date

\newcount\myyear

\newcommand{\addyears}[1]{%
  \myyear=\csuse{date@mydate@y}\relax
  \advance\myyear by #1\relax
  \formatdate{\csuse{date@mydate@d}}{\csuse{date@mydate@m}}{\myyear}%
}

\begin{document}

Year \addyears{0} was the first day of the 19th century, duh! Five
years later was \addyears{5}.        % 01/01/1805

\end{document}
(\getdateyear adds a check to see if the date has been defined, so it can't be used for assignment purposes.)

Regards
Nicola Talbot
arobase
Posts: 33
Joined: Sat Apr 14, 2012 7:46 pm

Re: Increment Date

Post by arobase »

Exactly, thanks!
Post Reply