# ISO Date Format

I have done a search on this forum and on the internet and have not found the answer to my question. I am looking to use an ISO date format such as 2018W083 for today (2018-02-21) in my reports. I use the isodate package now for my dates, \usepackage[iso]{isodate}.

If this is a duplicate question, please let me know. I could not find it.

• What is the meaning of W083? – Sigur Feb 21 '18 at 14:35
• Week 8 day 3. Day 1 is Monday and day 7 is Sunday. – Joe Ciras Feb 21 '18 at 14:37

This is (surprisingly) not trivial. There is Macro for week number but the implementation there seems to be slightly unreliable. If you are willing to use LuaLaTeX then you can make a system call to find the week number (and other parts of the date).

Note that the system library defines Sunday as 0, while ISO 8601 defines it as 7.

MWE:

\documentclass{article}
\usepackage{luacode}
\newcommand{\weektoday}{\printdate{\the\year}{\the\month}{\the\day}}
\newcommand{\printdate}[3]{%
\luaexec{
timestamp = os.time{year=#1, month=#2, day=#3}
daynr = os.date("\%w",timestamp)
if daynr == "0" then daynr = "7" end
tex.sprint(os.date("\%YW\%V-",timestamp)..daynr)
}
}
\begin{document}
Today: \weektoday

Other date: \printdate{2018}{3}{4}
\end{document}


Result:

Compatibility note: on Windows the %V format is not implemented. Instead you can use %U(first Sunday starts week 0) or %W(first Monday starts week 0), however both are different from the ISO standard (first Thursday determines week 1). You can calculate the ISO week number manually in Lua but in that case you may just as well use a pure LaTeX solution.

• Thank you. I will try this when I get back to my office. – Joe Ciras Feb 21 '18 at 15:21
• I have been unable to load the luacode package in TexLive. Any suggestions? – Joe Ciras Feb 21 '18 at 18:11
• Just to be sure: did you use lualatex instead of pdflatex/xelatex? If you don't have the luacode package I would suggest to install it :) are you using Linux or Mac or Windows? What type of TeX Live installation did you do? – Marijn Feb 21 '18 at 18:27
• I compiles your program and received only: Today: and Other date: with no date. I am using a Windows computer. It looks like your program is for a mac. – Joe Ciras Feb 21 '18 at 21:39
• I tested it on Linux, however the os.time and os.date functions should also be available on Windows. Did you get any warnings or messages? – Marijn Feb 21 '18 at 23:28