I want to extract the year (or day or month) of a date which is stored as ISO 8601 in a database.
My MWE looks like:
\documentclass{article}
\usepackage{xstring}
\usepackage{datatool}
\newcommand{\myload}[3][1]{%
\DTLgetvalue
{\thevalue}
{#2}
{#1}
{\dtlcolumnindex
{#2}
{#3}}%
}
%\get{<DATABASE>}{<FIELD>}
\newcommand{\get}[3][1]{%
\myload[#1]{#2}{#3}
\thevalue%
}
% https://tex.stackexchange.com/a/42027/98739
\newcommand{\dfgExtractYear}[1]{\StrBefore[1]{#1}{-}}%
\newcommand{\dfgExtractMonth}[1]{\StrBetween[1,2]{#1}{-}{-}}%
\newcommand*{\dfgExtractDay}[1]{\StrBehind[2]{#1}{-}}%
% database
\DTLnewdb{name}
\DTLnewrow{name}
\DTLnewdbentry{name}{dateBirth}{1980-12-04}
\begin{document}
date: \get{name}{dateBirth}\ % works
Year: \dfgExtractYear{YYYY-MM-DD}\% works
Day: \dfgExtractDay{YYYY-MM-DD}\% works
Month: \dfgExtractMonth{YYYY-MM-DD}\% works
Only Year: \dfgExtractMonth{\get{name}{dateBirth}}% does not work
\end{document}
This is the result:
How can I combine the extraction code of the date-part with the entry of the database?
