Text Formattingdatetime2 date style yyyymmdd

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
wjfeeney
Posts: 9
Joined: Sun Aug 06, 2023 9:02 am

datetime2 date style yyyymmdd

Post by wjfeeney »

Using the {datetime2} package, what is the code to use the date style yyyymmdd? Currently, I am using

Code: Select all

\DTMsetdatestyle{default}\today
which displays 2023-08-05. I would like to get rid of the hyphen separators so the date will display as 20230805.

Thanks in advance.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

datetime2 date style yyyymmdd

Post by rais »

See `texdoc datetime2', section `Package options' starts with all the separators. ;)

KR
Rainer
wjfeeney
Posts: 9
Joined: Sun Aug 06, 2023 9:02 am

datetime2 date style yyyymmdd

Post by wjfeeney »

I have reviewed the datetime2 documentation, but I am not finding the solution.

I tried this in my preamble:

Code: Select all

\usepackage[USenglish]{datetime2}
\DTMnewdatestyle{mydate}{\THEYEAR\THEMONTH\THEDAY}
but this doesn't work.

What do I put after {mydate} to output the date without separators, e.g., 20230805?
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

datetime2 date style yyyymmdd

Post by rais »

wjfeeney wrote:

Code: Select all

\usepackage[USenglish]{datetime2}
\DTMnewdatestyle{mydate}{\THEYEAR\THEMONTH\THEDAY}
you appear to be mixing commands from the older datetime package with commands from the current datetime2 package, that's not a good idea.
According to datetime2's documentation, \DTMnewdatestyle should be used to redefine \DTMdisplaydate and \DTMDisplaydate, e.g.,

Code: Select all

\DTMnewdatestyle{mydate}{%
  \renewcommand*\DTMdisplaydate[4]{##1##2##3}%
  \renewcommand*\DTMDisplaydate{\DTMdisplaydate}%
}
Just defining a new style's probably not enough, most likely you need to set it, as well

Code: Select all

\DTMsetdatestyle{mydate}
should do just that.

I was thinking of a somewhat simpler approach, though:

Code: Select all

\documentclass{article}
\usepackage[datesep={}]{datetime2}
\begin{document}
\today
\end{document}
hence the previous hint about `package options'.

KR
Rainer
wjfeeney
Posts: 9
Joined: Sun Aug 06, 2023 9:02 am

datetime2 date style yyyymmdd

Post by wjfeeney »

This works, awesome! Thanks.
Post Reply