56

This should be a easy question, but I didn't find answer from googling. The date format I wan is: Month(letter), Year(numerical). For example, I want: November, 2014. Of course, I can manually achieve this requirement. But I think LaTeX can do better. Any ideas will be greatly appreciated. Thanks!

2
  • 1
    How do you want to use it? Do you want to specify it using a regular date-like format, yet LaTeX should output it using (only) "Month, Year"? As in, \mydate{2014/11/14} should output November, 2014?
    – Werner
    Nov 14, 2014 at 18:37
  • Thanks Werner for the swift reply! I am not sure how to specify it, but the ultimate output I want is: month, year. For example: November, 2014. If I put \date{\today}, it will contain date which I do not want.
    – Daryl
    Nov 14, 2014 at 18:43

4 Answers 4

62

You can use the datetime package to customize the formatting; a little complete example:

\documentclass{book}
\usepackage{datetime}

\newdateformat{monthyeardate}{%
  \monthname[\THEMONTH], \THEYEAR}

\begin{document}

\monthyeardate\today

\end{document}

produces

enter image description here

0
31

With datetime2 package, there is at least two ways to achieve this. The first is a bit similar to the answer by Gonzalo:

\documentclass[english]{book}
\usepackage{datetime2}

\makeatletter
\newcommand{\monthyeardate}{%
  \DTMenglishmonthname{\@dtm@month}, \@dtm@year
}
\makeatother

\begin{document}

\monthyeardate

\end{document}

datetime2 the first way

The other way, I think, is more LaTeXian:

\documentclass{book}
\usepackage[en-US]{datetime2}

\begin{document}

\today

\DTMlangsetup{showdayofmonth=false}
\today
\DTMlangsetup{showdayofmonth=true}

\today

\end{document}

datetime2 the second way

Some notes:

  • For the first way to work, english parameter for \documentclass seems to be required. Alternatively, english can be omitted and en-US or en-GB given for datetime2 as \usepackage[en-US]{datetime2}
  • The second way requires en-US or en-GB even when english has been given for \documentclass.
  • The ways were tested with pdflatex, version pdfTeX 3.14159265-2.6-1.40.16 (TeX Live 2015).

More details are provided in:

1
  • This seems to be outdated. One way to get it in the new paradigm is \usepackage[calc]{datetime2}, then \DTMsavenow{mytoday} and then \DTMmonthname{\DTMfetchmonth{mytoday}}~\DTMfetchday{mytoday}, \DTMfetchyear{mytoday} (obviously, leave out the fetching of the day if you don't want that). Jun 13, 2021 at 10:11
22

A simple solution that requires no extra packages is the following:

\documentclass{article}

\renewcommand{\today}{\ifcase \month \or January\or February\or March\or %
April\or May \or June\or July\or August\or September\or October\or November\or %
December\fi, \number \year} 

\begin{document}
\today
\end{document}

The result:

4
  • 6
    This is the best answer, in my opinion. Apr 22, 2020 at 20:53
  • 2
    This is the worst answer, in my opinion.
    – MehmedB
    Jul 12, 2020 at 10:18
  • 8
    Both of your comments are not helpful, in my opinion, as they don't say 'why' May 8, 2021 at 12:22
  • 2
    I would propose to simply create a new command rather than redefining \today Sep 23, 2021 at 6:04
1

To make it easy for people new to Latex, I shall add a cw answer here incorporating Atiyah Elsheikh's comment on luchonacho's answer (this seems to be the best of both worlds to me).

\documentclass{article}

\newcommand{\monthyeardate}{\ifcase \month \or January\or February\or March\or %
April\or May \or June\or July\or August\or September\or October\or November\or %
December\fi, \number \year} 

\title{}
\author{}
\date{\monthyeardate}

\begin{document}
\maketitle
\end{document}
1
  • Correct me if this is totally wrong. I am not a TeXnician. Jan 14, 2023 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .