# datetime2 define dates “globally” outside of \begin{document}

When using the datetime package, I could define dates "globally" like this:

\newdate{sample}{03}{09}{2016}
\begin{document}
\displaydate{sample}
\end{document}


Can anyone tell me, how this is possible with datetime2 library because I just don't get it somehow...

Full document:

\documentclass[a4paper, 12pt, DIV=calc, headings=small]{scrreprt}
%Used packages
\usepackage[UKenglish]{babel}
\usepackage[utf8]{luainputenc}
\usepackage{datetime}

%Other definitions
\pagenumbering{arabic}

\newdate{sample}{31}{01}{2017}

\begin{document}
\displaydate{sample}
\end{document}

• Did you read section 4 Storing and Using Dates and Times in the datetime2 documentation? – Ulrike Fischer Sep 4 '16 at 17:02
• I must have just read over it... :( But still thanks for the info. – FranzHuber23 Sep 4 '16 at 17:38
• In this question (the link) I just wanted to asked how to reformat today's date... Here I wanted to know how to define dates in the datetime2 library. So I guess not. – FranzHuber23 Sep 4 '16 at 18:10
• I don't agree that the questions are duplicates. I've posted on meta – Nicola Talbot Sep 6 '16 at 12:40

Solution is here:

\documentclass{article}

\usepackage[UKenglish]{babel}
\usepackage[useregional]{datetime2}

\DTMlangsetup[en-GB]{ord=raise,monthyearsep={,\space}}

\DTMsavedate{sample}{2017-01-31}

\begin{document}
\DTMusedate{sample}

\end{document}


Thanks to Nicola Talbot