[Tex/LaTex] Print current date without updating

datetime

I am trying to keep a journal-type file using TeX. I would like to create a template in which I need not manually enter the date each day. Example:

January 26, 2014
Entry for the day here.

January 27, 2014
Entry for the day here.

January 28, 2014
Entry for the day here.

I would ideally like to automate this to:

\today <— Set date to January 26, 2014 that does not change when compiling next day
Entry for the day here.

\today <— Set date to January 27, 2014 that does not change when compiling next day
Entry for the day here.

\today <— Set date to January 28, 2014 that does not change when compiling next day
Entry for the day here.

Any help would be greatly appreciated!
Best wishes,
~Joco

Best Answer

I've seen so many crazy things made with LaTeX, i wouldn't say that something is impossible, but you have to use LuaLaTeX for my solution.

At first make a file,call it datetime.lua and add the following line.

datetime.lua

t = {}

All dates are saved in a lua table. You can edit them later in this file.

main.tex

\documentclass{scrartcl}
\usepackage{luacode}

\begin{luacode}
 require("datetime")

 function getdate(c)
  d = os.date("%d %B, %Y")   
   if (c <= #t) then
    tex.print(t[c])
   else
    file = io.open("datetime.lua", "a")
    file:write("t[".. c .."] = '" .. d .. "'; ")
    file:flush()
    file:close()
    tex.print(d)
   end
 end
\end{luacode}

\newcounter{date}
\addtocounter{date}{1}

\newcommand{\customdate}{\directlua{getdate(\number\value{date})}\stepcounter{date}}

\begin{document}

\customdate

\end{document}

I am using a counter to make a referenz to the date position. The value is passed to a simple lua function. If the date is already saved, it is loaded from the table and if not, it is written to the datetime file and the current date is printed.

Edit: You can get a problem when you change the order. (reorder the numbers in datetime.lua)