2

I want to change date format for date string

Ex. /changeformat{'06/23/2016'} and result = 23 June 2016

8
\documentclass{article}

\def\changeformat#1{\xchangeformat#1\relax}
\def\xchangeformat#1/#2/#3\relax{%
#2 %
\ifcase#1 \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
\ #3}

\begin{document}

\changeformat{06/23/2016} and result = 23 June 2016

\end{document}
| improve this answer | |
  • After I've tried it was display [July] instead of [June] After check It seems that it haven't [April] – user3863074 Jun 24 '16 at 2:53
  • @user3863074 oops, fixed:-) – David Carlisle Jun 24 '16 at 9:19
5

Compile with lualatex. Uses standard os.date() library

Mathematica graphics

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[margin=1in]{geometry}
\usepackage{luacode}

\begin{luacode*}
function conv(t)
local m = tonumber(t:sub(1,2))
local d = tonumber(t:sub(4,5))
local y = tonumber(t:sub(7,10))
whc     = os.time({year=y, month=m, day=d})

tex.print(os.date("%d %B %Y",whc))
end
\end{luacode*}

\begin{document}    
06/23/2016 is \directlua{conv('06/23/2016')}

12/30/2016 is \directlua{conv('12/30/2016')}    
\end{document}
| improve this answer | |
3

This solution uses datetime2, so you can apply the official format for a given country, or any format you choose, with day of week.

Also, it works with any seperator of your choice, so if you can use 06/23/2016 ,06.23.2016 or whatever you throw at it.

The format-changing is done with xstring.

Output

enter image description here

Code

\documentclass[11pt, australian]{article}
\usepackage{babel}
\usepackage{xstring}
\usepackage[useregional, calc]{datetime2}
\newcommand{\changeformat}[1]{%
    \StrRight{#1}{4}[\myyear]%
    \StrLeft{#1}{2}[\mymonth]%
    \StrMid{#1}{4}{5}[\mydate]%
    \DTMdate{\myyear-\mymonth-\mydate}%
    }

\DTMusemodule{british}{en-GB} % Only neaded for extra languages.
\begin{document}

\changeformat{06/23/2016}

\DTMsetdatestyle{iso}
\changeformat{06/23/2016}

\DTMsetdatestyle{ddmmyyyy}
\changeformat{06.23.2016}


\DTMlangsetup[en-GB]{abbr}
\DTMsetstyle{en-GB}
\DTMsetup{showdow}
\changeformat{06/23/2016}
\end{document}
| improve this answer | |
1
\documentclass{scrartcl}

\renewcommand*\today{\number\day\space
  \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\space
  \number\year}

\begin{document}

\today

\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.