I frequently use the \formatdate{01}{02}{2016}
command to get a result like
Now I need the same thing, but without the day. I just need the month and year. Unfortunately, the \formatdate
command only accepts 3 parameters.
Is there a command that does the above but only with month and year?
Best Answer
It's better to switch to the new
datetime2
package, which replacesdatetime
. This example also requiresdatetime2-english
as thedatetime2
language modules are distributed separately.You can localise
\DTMlangsetup
:\DTMdate
has a more convenient interface and is able to compute the day of week if thecalc
package option is used (which makesdatetime2.sty
automatically loaddatetime2-calc.sty
), but it's robust and can't be used in an expandable context, such as writing information to an external file (e.g. the table of contents or bookmarks).For example, if
\DTMdate{2016-02-01}
is used in a sectioning command (such as\chapter
or\section
) it will be written to the.toc
file as\DTMdate{2016-02-01}
not asFebruary, 2016
(or whatever the style format is at that point). This means that the date will appear in the table of contents in the style currently in effect when the.toc
file is read by\tableofcontents
whereas the section heading will use whatever style is in effect at that point.Robust non-expandable material also can't be used in PDF bookmarks. The command will be discarded and you'll be left with just the argument.
For example:
This triggers the warning:
The bookmark shows the section as "2016-02-01", the table of contents shows the section as "1st February, 2016" and the section header shows as "February, 2016".
If
\DTMdisplaydate
is used instead, the result is more consistent:The bookmarks, table of contents and section now all show the same "February, 2016", which is the style in effect when
\section
was used.