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)".

3
  • Please provide a full minimal working example (\begin{document} ... \end{document}) instead of a code fragment, which once copy past can be compiled.
    – Cfun
    Jul 4, 2016 at 21:56
  • Edited. It is compilable, although working is a bit of an issue at the moment.
    – DIWesser
    Jul 4, 2016 at 22:01
  • You'll have to forgive me screwing up your edit suggestions. I'm not quite used to to the stack exchanges UI yet.
    – DIWesser
    Jul 4, 2016 at 22:11

2 Answers 2

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}
5
  • 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 9, 2016 at 2: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 9, 2016 at 5:28
  • Does this help? pastebin.com/XKD1kzL3
    – DIWesser
    Jul 9, 2016 at 5: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 9, 2016 at 6: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, 2019 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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .