4

I'm trying to add a variable date to a variable number.

I'm currently trying to use the datetime2 package. I'm trying to get something like this (not actually working):

\documentclass[10pt]{article}  
\usepackage[calc, datesep=/]{datetime2}  

\DTMsavedate{ShootDate}{2016-05-20}  
\newcommand{\PaymentTurnAroundDays}{45}  

\begin{document}  
Payment will be made by \DTMusedate{ShootDate}{\PaymentTurnAroundDays}\ (within{\PaymentTurnAroundDays} of the day of the event(s)).  
\end{document} 

To render as:

Payment will be made by 2016/07/04 (within 45 of the day of the event(s)).

This should add "shoot date (2016/05/20)" to "payment turn around in days(45)".

2 Answers2

3
\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{newDate}{\number\daycount}
    \DTMusedate{newDate}
 }

\begin{document}
Payment will be made by \dueDate{\PaymentTurnAroundDays} (within {\PaymentTurnAroundDays} of the day of the event(s)).     
\end{document}
alwaysask
  • 2,248
  • 13
  • 16
  • I've finally had the chance to test this out. I notice that, if I try and add the date in two separate spots, the second one will have date*2 added. Is there a way to prevent this? – DIWesser Jul 09 '16 at 02:59
  • @DIWesser I don't quite understand what you're trying to do. Please post an MWE with the issue on a pastebin-like site and paste here the link. – alwaysask Jul 09 '16 at 05:28
  • Does this help? http://pastebin.com/XKD1kzL3 – DIWesser Jul 09 '16 at 05:44
  • @DIWesser Then we'll use another name for the new date to store the result in (instead of overwriting the initial one). I modified the answer. Does it work now for your needs? – alwaysask Jul 09 '16 at 06:45
  • 1
    Please don't ask for MWEs to be posted to pastebin sites and linked. Please suggest editing the question or asking a new one with a link back here, as appropriate. – cfr Oct 25 '19 at 22:36
1

Here is my suggestion (it's not very flexible but it works) using the package datenumber instead of datetime2.

\documentclass[10pt]{article}  
\usepackage{datenumber}  

\newcommand{\PaymentTurnAroundDays}{45}  
\newcommand{\pnext}{%
\thedateyear/%
\ifnum\value{datemonth}<10 0\fi
\thedatemonth/%
\ifnum\value{dateday}<10 0\fi
\thedateday%
\nextdate
}

\begin{document}  

\setdate{2016}{05}{20} %ShootDate
\addtocounter{datenumber}{\PaymentTurnAroundDays}%
\setdatebynumber{\thedatenumber}%
Payment will be made by \pnext{} (within \PaymentTurnAroundDays{} of the day of the event(s)).

\end{document}
Cfun
  • 1,840