Using the document title to get the correct date

I create a lot of handouts and the like for my students using LaTeX. I find that I forget to update the date field, and so I often give out handouts with the incorrect date on the top. This is a bit of a nuisance and would be easily fixed by me being slightly less lazy.

However, I save the source files in the format [YY-MM-DD]_DocumentType.tex, e.g., [18-02-14]_Handout.tex and [18-02-14]_Plan.tex are the handout and plan for my class tomorrow.

Does anyone know of a way that I could use the name of the file to automatically generate the corresponding date within the compiled document?

• – Werner Feb 13 '18 at 18:27

I created the file [18-02-14]_james.tex (on February 13).

\documentclass{article}

\def\splitjobname[#1-#2-#3]#4\relax{%
\year=\numexpr2000+#1\relax
\month=#2
\day=#3
}
\expandafter\splitjobname\jobname\relax

\begin{document}

\today

\end{document}