LyXUse a date in various formats

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Post Reply
mvw
Posts: 5
Joined: Fri Jul 12, 2013 3:11 am

Use a date in various formats

Post by mvw »

Dear all,

Sorry to trouble you again, but I am stuck with the following. In my documentation I frequently use a particular date, which is not "today's date". I may want to refer to this date in various formats. For example, in a table I would like it to show as "26/04/13" - a nice short format to conserve table space. While in the main text I may want to use "26 April 2013".

Since the date will be referenced frequently, I thought to assign it to a macro. This is what I have so far:

In the preamble:

Code: Select all

\usepackage{datetime}
\newdate{mylongdate}{26}{04}{2013}
In the actual document:

Code: Select all

This document refers to the work performed on \displaydate{mylongdate}.
Which then shows as:

Code: Select all

This document refers to the work performed on Friday 26th April, 2013.
Now, if I change the \usepackage{datetime} to \usepackage[ddmmyyyy]{datetime}, I can see that this influences the output to "26/04/2013". Great! However, if I want to use the "mylongdate" macro somewhere else in my document, it will always display the same way.

I would like to accomplish something like this in the preamble:

Code: Select all

\newdate{mydate}{26}{04}{2013}
\newcommand*{\mylongdate}{\formatdate[long]{mydate}}
\newcommand*{\myshortdate}{\formatdate[ddmmyy]{mydate}}
I think I am approaching this the wrong way, as I have been looking everywhere but don't seem to be able to find anything that resembles what I am thinking about doing.

Perhaps someone can steer me in the direction on how to tackle the problem, not necessarily following my thought pattern.

Thank you.
Last edited by cgnieder on Mon Jul 15, 2013 11:01 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

mvw
Posts: 5
Joined: Fri Jul 12, 2013 3:11 am

Use a date in various formats

Post by mvw »

I think I (finally) worked it out.

In the document preamble, I now have:

Code: Select all

\usepackage[australian]{babel}
\usepackage[dayofweek]{datetime}
\newdate{mydate}{26}{04}{2013}
In the actual document I use this:

Code: Select all

This is one format of the date \ddmmyydate\displaydate{mydate} and this is another format \longdate\displaydate{mydate}.
The result is:

Code: Select all

This is one formate of the date 26/04/13 and this is another format Friday 26 April, 2013.
The only nagging thing now is to get rid of the "," after April. I thought I read somewhere on how to do that, but cannot find it anymore. If anyone knows, I would be keen to find out.

Marc.
Post Reply