I have two different dates in my LaTeX document which are not current dates (dates which come in my LaTeX template from the web form).
They look like this: 2016-03-31
, but I want these dates be in the format dd/mm/yyyy
.
What I'm doing right now is using the package \usepackage[ddmmyyyy]{date time}
and put inside the \date{}
in my dates, but it doesn't change the format of the dates. How do I change the format of the dates correctly?
[Tex/LaTex] Date formatting: Changing from web format to another format
datetimeformatting
Related Solutions
Here is a prototype in LaTeX3; the data about tomorrow is available in the integer variables
\l_tomorrow_day_int
\l_tomorrow_month_int
\l_tomorrow_year_int
The code follows; the final macro is just an example of how the data can be used, possibly in connection with datetime
.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\prop_new:N \g_tomorrow_months_prop
\bool_new:N \l_tomorrow_leap_bool
\int_new:N \l_tomorrow_day_int
\int_new:N \l_tomorrow_month_int
\int_new:N \l_tomorrow_year_int
\prop_gput:Nnn \g_tomorrow_months_prop { 1 } { 31 }
\prop_gput:Nnn \g_tomorrow_months_prop { 2 } { \bool_if:NTF \l_tomorrow_leap_bool { 29 } { 28 } }
\prop_gput:Nnn \g_tomorrow_months_prop { 3 } { 31 }
\prop_gput:Nnn \g_tomorrow_months_prop { 4 } { 30 }
\prop_gput:Nnn \g_tomorrow_months_prop { 5 } { 31 }
\prop_gput:Nnn \g_tomorrow_months_prop { 6 } { 30 }
\prop_gput:Nnn \g_tomorrow_months_prop { 7 } { 31 }
\prop_gput:Nnn \g_tomorrow_months_prop { 8 } { 31 }
\prop_gput:Nnn \g_tomorrow_months_prop { 9 } { 30 }
\prop_gput:Nnn \g_tomorrow_months_prop { 10 } { 31 }
\prop_gput:Nnn \g_tomorrow_months_prop { 11 } { 30 }
\prop_gput:Nnn \g_tomorrow_months_prop { 12 } { 31 }
\cs_new_protected:Npn \tomorrow_check_leap:n #1
{
\int_compare:nTF { 0 = \int_mod:nn { #1 } { 4 } }
{% possibly a leap year
\int_compare:nTF { 0 = \int_mod:nn { #1 } { 100 } }
{% possibly not a leap year
\int_compare:nTF { 0 = \int_mod:nn { #1/100 } { 4 } }
{% leap year
\bool_set_true:N \l_tomorrow_leap_bool
}
{% not leap year
\bool_set_false:N \l_tomorrow_leap_bool
}
}
{% leap year
\bool_set_true:N \l_tomorrow_leap_bool
}
}
{% not leap year
\bool_set_false:N \l_tomorrow_leap_bool
}
}
\cs_new_protected:Npn \tomorrow_set_tomorrow:nnn #1 #2 #3
{
\int_compare:nT { #2 = 2 } { \tomorrow_check_leap:n { #3 } }
\int_set:Nn \l_tomorrow_day_int { #1 }
\int_set:Nn \l_tomorrow_month_int { #2 }
\int_set:Nn \l_tomorrow_year_int { #3 }
\__tomorrow_incr_day:
}
\cs_new_protected:Npn \__tomorrow_incr_day:
{
\int_incr:N \l_tomorrow_day_int
\int_compare:nT
{ \l_tomorrow_day_int > \prop_get:NV \g_tomorrow_months_prop \l_tomorrow_month_int }
{
\int_set:Nn \l_tomorrow_day_int { 1 }
\__tomorrow_incr_month:
}
}
\cs_new_protected:Npn \__tomorrow_incr_month:
{
\int_incr:N \l_tomorrow_month_int
\int_compare:nT { \l_tomorrow_month_int > 12 }
{
\int_set:Nn \l_tomorrow_month_int { 1 }
\int_incr:N \l_tomorrow_year_int
}
}
\cs_generate_variant:Nn \prop_get:Nn { NV }
\NewDocumentCommand{\printtomorrowof}{mmm}
{
\tomorrow_set_tomorrow:nnn { #1 } { #2 } { #3 }
Today~it~is~
\int_to_arabic:n { #3 }/
\int_to_arabic:n { #2 }/
\int_to_arabic:n { #1 },~
tomorrow~it~is~
\int_to_arabic:n { \l_tomorrow_year_int }/
\int_to_arabic:n { \l_tomorrow_month_int }/
\int_to_arabic:n { \l_tomorrow_day_int }
\par
}
\ExplSyntaxOff
\begin{document}
\printtomorrowof{\day}{\month}{\year}
\printtomorrowof{30}{10}{2012}
\printtomorrowof{31}{10}{2012}
\printtomorrowof{31}{12}{2012}
\printtomorrowof{28}{2}{2012}
\printtomorrowof{28}{2}{2013}
\printtomorrowof{28}{2}{1900}
\printtomorrowof{28}{2}{2000}
\end{document}
As you see, leap years are correctly recognized. Only Gregorian calendar, of course.
In order to define a suitable \tomorrow
command, you can add (before \ExplSyntaxOn
) a babel
version
\NewDocumentCommand{\tomorrow}{}
{
\tomorrow_set_tomorrow:nnn { \day } { \month } { \year }
\group_begin:
\day = \l_tomorrow_day_int
\month = \l_tomorrow_month_int
\year = \l_tomorrow_year_int
\today
\group_end:
}
or a datetime
version (requires package datetime
, of course)
\NewDocumentCommand{\tomorrow}{}
{
\tomorrow_set_tomorrow:nnn { \day } { \month } { \year }
\formatdate { \l_tomorrow_day_int }
{ \l_tomorrow_month_int }
{ \l_tomorrow_year_int }
}
This is, of course, overkill if one wants only tomorrow's date. The macros actually allow to compute any date from a given one, given the interval (positive or negative). One might make expandable also the "reverse" from a Julian date to the form "Day/Month/Year", but it would be very slow.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\DeclareExpandableDocumentCommand{\juliandate}{ m m m }
{
\juliandate_calc:nnnn { #1 } { #2 } { #3 } { \use:n }
}
\NewDocumentCommand{\storejuliandate}{ s m m m m }
{
\IfBooleanTF{#1}
{
\juliandate_calc:nnnn { #3 } { #4 } { #5 } { \cs_set:Npx #2 }
}
{
\juliandate_calc:nnnn { #3 } { #4 } { #5 } { \cs_new:Npx #2 }
}
}
\cs_new:Npn \juliandate_calc:nnnn #1 #2 #3 #4 % #1 = day, #2 = month, #3 = year, #4 = what to do
{
#4
{
\int_eval:n
{
#1 +
\int_div_truncate:nn { 153 * (#2 + 12 * \int_div_truncate:nn { 14 - #2 } { 12 } - 3) + 2 } { 5 } +
365 * (#3 + 4800 - \int_div_truncate:nn { 14 - #2 } { 12 } ) +
\int_div_truncate:nn { #3 + 4800 - \int_div_truncate:nn { 14 - #2 } { 12 } } { 4 } -
\int_div_truncate:nn { #3 + 4800 - \int_div_truncate:nn { 14 - #2 } { 12 } } { 100 } +
\int_div_truncate:nn { #3 + 4800 - \int_div_truncate:nn { 14 - #2 } { 12 } } { 400 } -
32045
}
}
}
\tl_new:N \l__juliandate_g_tl
\tl_new:N \l__juliandate_dg_tl
\tl_new:N \l__juliandate_c_tl
\tl_new:N \l__juliandate_dc_tl
\tl_new:N \l__juliandate_b_tl
\tl_new:N \l__juliandate_db_tl
\tl_new:N \l__juliandate_a_tl
\tl_new:N \l__juliandate_da_tl
\tl_new:N \l__juliandate_y_tl
\tl_new:N \l__juliandate_m_tl
\tl_new:N \l__juliandate_d_tl
\int_new:N \l_juliandate_day_int
\int_new:N \l_juliandate_month_int
\int_new:N \l_juliandate_year_int
\cs_new:Npn \__juliandate_set:nn #1 #2
{
\tl_set:cx { l__juliandate_#1_tl } { \int_eval:n { #2 } }
}
\cs_new:Npn \__juliandate_use:n #1
{
\tl_use:c { l__juliandate_#1_tl }
}
\cs_new_protected:Npn \juliandate_reverse:n #1
{
\__juliandate_set:nn { g }
{ \int_div_truncate:nn { #1 + 32044 } { 146097 } }
\__juliandate_set:nn { dg }
{ \int_mod:nn { #1 + 32044 } { 146097 } }
\__juliandate_set:nn { c }
{ \int_div_truncate:nn { ( \int_div_truncate:nn { \__juliandate_use:n { dg } } { 36524 } + 1) * 3 } { 4 } }
\__juliandate_set:nn { dc }
{ \__juliandate_use:n { dg } - \__juliandate_use:n { c } * 36524 }
\__juliandate_set:nn { b }
{ \int_div_truncate:nn { \__juliandate_use:n { dc } } { 1461 } }
\__juliandate_set:nn { db }
{ \int_mod:nn { \__juliandate_use:n { dc } } { 1461 } }
\__juliandate_set:nn { a }
{ \int_div_truncate:nn { ( \int_div_truncate:nn { \__juliandate_use:n { db } } { 365 } + 1) * 3 } { 4 } }
\__juliandate_set:nn { da }
{ \__juliandate_use:n { db } - \__juliandate_use:n { a } * 365 }
\__juliandate_set:nn { y }
{
\__juliandate_use:n { g } * 400 +
\__juliandate_use:n { c } * 100 +
\__juliandate_use:n { b } * 4 +
\__juliandate_use:n { a }
}
\__juliandate_set:nn { m }
{ \int_div_truncate:nn { \__juliandate_use:n { da } * 5 + 308 } { 153 } - 2 }
\__juliandate_set:nn { d }
{ \__juliandate_use:n { da } - \int_div_truncate:nn { (\__juliandate_use:n { m } + 4) * 153 } { 5 } + 122 }
\int_set:Nn \l_juliandate_year_int
{ \__juliandate_use:n { y } - 4800 + \int_div_truncate:nn { \__juliandate_use:n { m } + 2 } { 12 } }
\int_set:Nn \l_juliandate_month_int
{ \int_mod:nn { \__juliandate_use:n { m } + 2 } { 12 } + 1 }
\int_set:Nn \l_juliandate_day_int
{ \__juliandate_use:n { d } + 1 }
}
\cs_generate_variant:Nn \juliandate_reverse:n { x }
\NewDocumentCommand{\showday}{ m }
{
\juliandate_reverse:n { #1 }
\int_to_arabic:n { \l_juliandate_day_int }-
\int_to_arabic:n { \l_juliandate_month_int }-
\int_to_arabic:n { \l_juliandate_year_int }
}
\NewDocumentCommand{\tomorrow}{ }
{
\group_begin:
\juliandate_reverse:x { \juliandate_calc:nnnn { \day + 1 } { \month } { \year } { \use:n } }
\day = \l_juliandate_day_int
\month = \l_juliandate_month_int
\year = \l_juliandate_year_int
\today
\group_end:
}
\NewDocumentCommand{\tomorrowof}{ m m m }
{
\group_begin:
\juliandate_reverse:x { \juliandate_calc:nnnn { #1 + 1 } { #2 } { #3 } { \use:n } }
\day = \l_juliandate_day_int
\month = \l_juliandate_month_int
\year = \l_juliandate_year_int
\today
\group_end:
}
\ExplSyntaxOff
\begin{document}
\juliandate{18}{12}{2012}
\storejuliandate*{\x}{18}{12}{2012}\x
\storejuliandate*{\x}{1}{1}{1900}\x
\showday{2456280}
\showday{2415021}
\tomorrow
\tomorrowof{31}{12}{2012}
\tomorrowof{28}{2}{2012}
\tomorrowof{29}{2}{2012}
\tomorrowof{28}{2}{2013}
\tomorrowof{28}{2}{1900}
\end{document}
Update #2 (biblatex
>= 3.10)
Yet again new conventions in biblatex
3.10. Now edtf
has been replaced by iso
.
Updated MWE:
\documentclass[letterpaper, 11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{filecontents}{test.bib}
@online{Bonding,
author = {Stu Borman},
title = {Spying On Bond Making In Solution},
date = {2015-02-19},
url = {http://cen.acs.org/articles/93/i8/Spying-Bond-Making-Solution.html},
urldate = {2015-03-03},
addendum= {All about dicyanoaurate, has links to papers.}
}
\end{filecontents}
\usepackage[backend=biber,style=chem-rsc,articletitle=true,urldate=iso,date=iso,seconds=true]{biblatex}
\addbibresource{test.bib}
\begin{document}
Foo Bar Baz
\nocite{*}
\printbibliography[heading = none]
\end{document}
If all date formats have to be in ISO format (not only date
and urldate
) you can simply use alldates=iso
instead of urldate=iso
and date=iso
.
Update #1 (biblatex
>= 3.5)
As of biblatex
3.5, iso8601
is deprecated and edtf
together with seconds=true
should be used.
Using day
, month
and year
as fields is also deprecated, so you should use the field
date = {2015-02-19},
in your .bib
file instead of the three
year = 2015,
month = 02,
day = 19,
Updated MWE:
\documentclass[letterpaper, 11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{filecontents}{test.bib}
@online{Bonding,
author = {Stu Borman},
title = {Spying On Bond Making In Solution},
date = {2015-02-19},
url = {http://cen.acs.org/articles/93/i8/Spying-Bond-Making-Solution.html},
urldate = {2015-03-03},
addendum= {All about dicyanoaurate, has links to papers.}
}
\end{filecontents}
\usepackage[backend=biber,style=chem-rsc,articletitle=true,urldate=edtf,date=edtf,seconds=true]{biblatex}
\addbibresource{test.bib}
\begin{document}
Foo Bar Baz
\nocite{*}
\printbibliography[heading = none]
\end{document}
If all date formats have to be in ISO format (not only date
and urldate
) you can simply use alldates=edtf
instead of urldate=edtf
and date=edtf
.
Original answer
Add the options urldate=iso8601
and date=iso8601
when loading biblatex
(and remember to add the leading zeroes in fields like month
when needed).
MWE:
\documentclass[letterpaper, 11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{filecontents}{test.bib}
@online{Bonding,
author = {Stu Borman},
title = {Spying On Bond Making In Solution},
year = 2015,
month = 02,
day = 19,
url = {http://cen.acs.org/articles/93/i8/Spying-Bond-Making-Solution.html},
urldate = {2015-03-03},
addendum= {All about dicyanoaurate, has links to papers.}
}
\end{filecontents}
\usepackage[backend=biber,style=chem-rsc,articletitle=true,urldate=iso8601,date=iso8601]{biblatex}
\addbibresource{test.bib}
\begin{document}
Foo Bar Baz
\nocite{*}
\printbibliography[heading = none]
\end{document}
BTW: Using \addbibresource
instead of \bibliography
is recommended with biblatex
.
If all date formats have to be in ISO format (not only date
and urldate
) you can simply use alldates=iso8601
instead of urldate=iso8601
and date=iso8601
.
Best Answer
This works out the box. If
-
appears as the date separator there's probably a 'wrong'redefinition of\dateseparator
.Please note date
datetime
isn't developed further -- Nicola Talbot has publisheddatetime2
about a year ago.Update
Here's a version that transforms
yyyy-mm-dd
input intodd/mm/yyyy
: