2

Continues for topic: Add (n) days to variable date

But i want to use ShootDate like variable and other format:

26/10/2019 + 15

14/11/2019 + 30

05/03/2020 + 45

Please help with macro.

Thank a lot

Minimal coding:

 \documentclass[10p]{article}
    \usepackage[calc,datesep=/]{datetime2}
     \DTMsavedate{ShootDate}{2016-05-20}
    \newcommand{\PaymentTurnAroundDays}{45}
    \newcount\daycount
    \newcommand{\dueDate}[1]{%
        \DTMsaveddateoffsettojulianday{ShootDate}{#1}\daycount
       \DTMsavejulianday{ShootDate}{\number\daycount}
       \DTMusedate{ShootDate}
    }

    \begin{document}

    Payment will be made by \dueDate{\PaymentTurnAroundDays} (within {\PaymentTurnAroundDays} of the day of the event(s)).

26/10/2019 + 15 day = ?

14/11/2019 + 30 day = ?

05/03/2020 + 45 day = ?
    \end{document}
latexforti
  • 2,091
  • 1
    Maybe you could tell us what input you'd like to produce what output. Right now, I don't really understand the question. – cfr Oct 25 '19 at 22:40
  • @cfr i updated my question. i want to calculate: 26/10/2019 + 15 day = ?, 14/11/2019 + 30 day = ?, 05/03/2020 + 45 day = ? with macro. Thanks – latexforti Oct 25 '19 at 23:01
  • 2
    So why can't you do it with the answers to your other question e.g. the one using datenumber? That package does exactly what you say you want to do. – cfr Oct 25 '19 at 23:07
  • @cfr i give example with package datenumber, but you can change and use other package. thanks – latexforti Oct 25 '19 at 23:12
  • 2
    What I mean is: why doesn't something like https://tex.stackexchange.com/a/318009 do what you need? Turn the date into a number, add what you need and turn the result back into a date. – cfr Oct 26 '19 at 01:29
  • @cfr in this link, ShootDate is fix, i want shootdate like variable. thanks – latexforti Oct 26 '19 at 02:51
  • 2
    But you can keep changing it, can't you? – cfr Oct 26 '19 at 03:33
  • i can't do it. I want to change \DTMsavedate{ShootDate}{2016-05-20} to variable ... – latexforti Oct 26 '19 at 04:01
  • What do you mean by a 'variable'? LaTeX3 has a concept of variables, but that's not relevant here. I don't understand what you mean. – cfr Oct 26 '19 at 04:09

1 Answers1

4

Best guess at what you want:

\documentclass[10pt]{article}
\usepackage[calc,datesep=/]{datetime2}
\newcount\daycount
\newcommand{\DueDate}[2]{%
  \DTMsavedate{ShootDate}{#1}%
  \DTMsaveddateoffsettojulianday{ShootDate}{#2}\daycount
  \DTMsavejulianday{ShootDate}{\number\daycount}%
  \DTMusedate{ShootDate}%
}

\begin{document}

26/10/2019 + 15 day = \DueDate{2019-10-26}{15}

14/11/2019 + 30 day = \DueDate{2019-11-14}{30}

05/03/2020 + 45 day = \DueDate{2020-03-05}{45}
\end{document}

output

Note this doesn't include any variables.

Quick version for inverted dates with forward slashes.

Note that I do NOT recommend this. I would stick to ISO format for input.

Caveat emptor ...

\documentclass[10pt]{article}
\usepackage[calc,datesep=/]{datetime2}
\newcount\daycount
\makeatletter
\newcommand{\DueDate}[2]{%
  \edef\tempa{\expandafter\date@aux#1\@nil}%
  \DTMsavedate{ShootDate}{\tempa}%
  \DTMsaveddateoffsettojulianday{ShootDate}{#2}\daycount
  \DTMsavejulianday{ShootDate}{\number\daycount}%
  \DTMusedate{ShootDate}%
}
\newcommand*\dateaux{}
\def\date@aux#1/#2/#3\@nil{#3-#2-#1}
\makeatother
\begin{document}

26/10/2019 + 15 day = \DueDate{26/10/2019}{15}

14/11/2019 + 30 day = \DueDate{14/11/2019}{30}

05/03/2020 + 45 day = \DueDate{05/03/2020}{45}
\end{document}

Produces the same output as above. Note you will get nonsense error messages if you input something which doesn't match the specified format.

cfr
  • 198,882
  • it's right that i want. Please change format \DueDate{2019-10-26} to \DueDate{26/10/2019} . Thanks – latexforti Oct 26 '19 at 04:58
  • 1
    @latexforti I don't recommend it, but you can do something quick and nasty like the above. Alternatively, there's probably a package for it somewhere, but all the ones I know are concerned with the typeset format of dates, rather than the input. (You probably want one of those to adjust the output, but that's just a question of reading the docs of datetime2 or whatever. I'm allergic to datetime2, so I won't even try to go there.) – cfr Oct 27 '19 at 00:39
  • Thank. can you create output format = Day/Month/Year. – latexforti Oct 27 '19 at 00:45
  • @latexforti See previous comment ^^. – cfr Oct 27 '19 at 00:47
  • @latexforti It's the same as for \today. The output will follow whatever global style you tell datetime2 to use for dates. Just don't ask me to tangle with datetime2. I'm using a locally-fixed copy of datetime because I could not understand how to do simple things with datetime2. – cfr Oct 27 '19 at 00:50