Dear All,
This is my first post to this forum and first of all I would like to wish all of you a Happy New Year.
Now, I have a very basic problem i latex:
My code:
\documentclass{article}
\usepackage{datetime}
\usepackage{advdate}
\begin{document}
\newdate{my_date}{\day}{\month}{\year}
\displaydate{my_date} \\
\AdvanceDate[5]
\displaydate{my_date}
\end{document}
Executed today produces:
Monday 3rd January, 2011
Saturday 8th January, 2011
I would like to store \today as a constant and be able to reference to the entry further in the document but it seems that \AdvanceDate modifies \today and my_date does not store the date before modification but a reference.
In other words, how can prevent system to change my_date?
Any suggestions appreciate.
Regards,
Gsks
General ⇒ How to store the date
NEW: TikZ book now 40% off at Amazon.com for a short time.

How to store the date
You could use a \savebox (though one problem is that this would prevent line breaks inside the date at later uses... but perhaps that's not a problem.)
Code: Select all
\documentclass{article}
\usepackage{datetime}
\usepackage{advdate}
\begin{document}
\noindent%
\newdate{my_date}{\day}{\month}{\year}%
\displaydate{my_date} \\
\newsavebox{\constantdate}\savebox{\constantdate}{\displaydate{my_date}}
\AdvanceDate[5]
\displaydate{my_date}\\
\usebox{\constantdate}
\end{document}
How to store the date
Thank you very much for the tip. It works. I am able to store the data. In fact the reason of my question is a task I have. I need to check if the changed date and current date are in the same month.
I modified a little the code above to store only monthname and added check condition.
The above code gives me (also visible in the attached file).
Different months: January vs January.
Different monthe: January vs February.
If I use \the\months instead of \monthname the result is also false.
Why? I am confused
Regards,
gsks
I modified a little the code above to store only monthname and added check condition.
Code: Select all
\documentclass{article}
\usepackage{datetime}
\usepackage{advdate}
\usepackage{ifthen}
\begin{document}
\noindent
\newsavebox{\mymonth}\savebox{\mymonth}{\monthname}
\AdvanceDate[5] \\
\ifthenelse{\equal{\usebox{\mymonth}}{\monthname}}{Dates in the same month.}{Different months: \usebox{\mymonth} vs \monthname.}
\AdvanceDate[30] \\
\ifthenelse{\equal{\usebox{\mymonth}}{\monthname}}{Dates in the same month.}{Different months: \usebox{\mymonth} vs \monthname.}
\end{document}
Different months: January vs January.
Different monthe: January vs February.
If I use \the\months instead of \monthname the result is also false.
Why? I am confused

Regards,
gsks
- Attachments
-
- wynik.jpg (14.56 KiB) Viewed 3399 times
How to store the date
\monthname is too complicated to compare using \equal. I suggest you store the numerical value of the month and compare that instead.
Regards
Nicola Talbot
Code: Select all
\documentclass{article}
\usepackage{datetime}
\usepackage{advdate}
\begin{document}
\edef\mymonth{\number\month}
\AdvanceDate[5]
\ifnum\month=\mymonth
Same month.
\else
Different month: \monthname[\mymonth] vs \monthname.
\fi
\AdvanceDate[30]
\ifnum\month=\mymonth
Same month.
\else
Different month: \monthname[\mymonth] vs \monthname.
\fi
\end{document}
Nicola Talbot
LaTeX Resources: http://www.dickimaw-books.com/latexresources.html
Creating a Minimal Example: http://www.dickimaw-books.com/latex/minexample/
Creating a Minimal Example: http://www.dickimaw-books.com/latex/minexample/