2

I have searched the isodate package and the datetime2 package to answer my question. I would like my date to be mm/dd/yyyy. The closest I have gotten is to have the date as dd/mm/yyyy. Could someone help me out.

I tried:

\usepackage[american,useregional=numeric]{datetime2}
\dateinputformat{american}
LaRiFaRi
  • 43,807

1 Answers1

3

You should pass the American english (USenglish) and numeric format options to isodate. This yields the output format mm/dd/yyyy:

01/21/2016

\documentclass{article}
\usepackage[USenglish,num]{isodate}
\begin{document}
\today
\end{document}

The same output under datetime2 (without defining your own date style):

\documentclass{article}
\usepackage[datesep={/}]{datetime2}
\DTMsetdatestyle{mmddyyyy}
\begin{document}
\today
\end{document}

Without any packages, you can just manage the printing yourself using \day, \month (in two-digit format) and \year explicitly:

\documentclass{article}

\makeatletter
\renewcommand{\today}{\two@digits{\number\month}/\two@digits{\number\day}/\number\year}
\makeatother

\begin{document}
\today

\end{document}

For calculations (like a two-digit year) on the date you can use the following:

01/21/16

\documentclass{article}

\usepackage{xparse}
\ExplSyntaxOn
  \cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff
\makeatletter
\renewcommand{\today}{%
  \two@digits{\number\month}/% MM
  \two@digits{\number\day}/% DD
  \calc{\number\year-100*trunc(\number\year/100,0)}}% YY
\makeatother

\begin{document}
\today

\end{document}
Werner
  • 603,163
  • You can set both separators in one go with datesep={/} if you like. – Nicola Talbot Jan 21 '16 at 18:20
  • The datetime2 suggestion above worked. The isodate solution still returned dd/mm/yyyy. – Joe Ciras Jan 21 '16 at 19:44
  • @JoeCiras: Not sure why. I've added a no-package option as well. – Werner Jan 21 '16 at 20:32
  • @Werner Just an additional question - in the manage yourself solution, how do you just have a two digit year? mm-dd-yy. I tried added \two@digits before the year statement but it looks like that command makes a one digit number a two digit number and does not truncate the date down to just two digits. Sorry for asking so many questions on this subject. I am new to customizing LaTeX. – Joe Ciras Feb 04 '16 at 11:46
  • @JoeCiras: See my updated answer. – Werner Feb 05 '16 at 02:08