1

I need to process a latex command if and only if the current date is between certain months, say between april 15 and june 15 of any given year. I imagine it's possible with datetime.sty but all the examples on the web seem to involve relative dates (i.e., the date relative to the current day) rather than absolute dates. Also I want the conditioning event to depend only on the day and month and not on the year. Is this possible? Thanks very much.

I've added my own answer, which is not elegant, but works. I didn't want to put it into a comment for obvious reasons.

\documentclass{minimal}
\usepackage{datenumber}
%#1-#2 is start month-day
%#3-#4 is end   month-day
%#5: do this if within the range
%#6  do this if outside the range
\newcounter{doIt}
\newcommand{\doInDateRange}[6]{
    \setcounter{doIt}{0}
    \ifnum\thedatemonth>#1
        \ifnum\thedateday>#2
            \setcounter{doIt}{1}
        \fi
    \fi
    \ifnum\thedatemonth<#3
        \ifnum\thedateday<#4
            \addtocounter{doIt}{1}
        \fi
    \fi
    \ifnum\value{doIt}=2
        #5
    \else
        #6
    \fi
}
\begin{document}
\doInDateRange{3}{20}{5}{22}{Your are within the date range}{You are outside the date range}\\
\doInDateRange{3}{22}{12}{31}{Your are within the date range}{You are outside the date range}\\
\doInDateRange{1}{1}{5}{22}{Your are within the date range}{You are outside the date range}
\end{document}
Leo Simon
  • 2,199
  • take a look at datetime2-calc – Sean Allred Apr 21 '16 at 03:05
  • This is a cute question and I am tempted to answer it but part of me thinks I shouldn't because some people on TeX.SX take exception to questions of the form "Please do this for me". You will get more help if you post some code showing what you have tried and give a minimal working example. At the very least it would be good if you gave a MWE showing how such a command might be used. –  Apr 21 '16 at 05:46
  • TeX offers the primitives \day and \month, both integers, so this is all doable. – Joseph Wright Apr 21 '16 at 06:04
  • 4
    I thought this question looked familiar: it is almost, but not quite, the same as http://tex.stackexchange.com/questions/290847/is-there-a-way-to-condition-output-on-a-given-date/290848#290848. A minor variation on the answers to this other post will solve this question. –  Apr 21 '16 at 06:08

0 Answers0