About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Latest news 2024-12-13: Ebook sale (12th December 2024 – 1st January 2025): cybercrime fiction short stories Unsocial Media and Smile for the Camera free; crime fiction short story The Briefcase free; short story noir crime fiction I’ve Heard the Mermaid Sing free; crime fiction novel The Private Enemy US$1.99; illustrated children’s story The Foolish Hedgehog US$0.99.

Calculating Ages

This document requires the sample people.csv file.
\documentclass[captions=tableheading]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{pgfkeys,pgfcalendar}
\usepackage{datatool}

\DTLloaddb{people}{people.csv}

\newcount\julianday
\newcount\juliantoday
\newcount\age

% Compute the Julian day number for today:
\pgfcalendardatetojulian{\year-\month-\day}{\juliantoday}%

\begin{document}
Ages as of \number\year-\number\month-\number\day\ are
listed in Table~\ref{tab:ages}.

\begin{table}[htbp]
\caption{Ages (as of \number\year-\number\month-\number\day)}
\label{tab:ages}
\centering
\begin{tabular}{lc}
\bfseries Name & \bfseries Age%
\DTLforeach*{people}%
 {\Forenames=forenames,\Surname=surname,\DoB=dob}%
 {%
    \\\Forenames\ \Surname &
    % Compute the Julian day number for the date of birth
    \pgfcalendardatetojulian{\DoB}{\julianday}%
    % Compute \age = (\juliantoday - \julianday)/365
    \age=\juliantoday
    \advance\age by -\julianday
    \divide\age by 365\relax
    \number\age
 }%
\end{tabular}
\end{table}

Non-ISO format:
\def\DoB{12/2/1995}%
\def\parsemdydate#1/#2/#3\endparsemdydate{#3-#1-#2}%
\pgfcalendardatetojulian{\expandafter\parsemdydate\DoB\endparsemdydate}{\julianday}%
% Compute \age = (\juliantoday - \julianday)/365
\age=\juliantoday
\advance\age by -\julianday
\divide\age by 365\relax
DoB = \DoB, age = \number\age.

\end{document}

Download calcage.tex or calcage.pdf.

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs