www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Add a duration (in Days) to a Date

reply Mil58 <peter_pinkness yahoo.fr> writes:
Hi all...
In the following example, i would to add the "diff" value (in 
days) to a certain date (or the today's date "auj") >>

import std.stdio;
import std.datetime;
import core.time : Duration;

void main()
{
   auto deb = DateTime(2019, 9, 5);
   auto auj = Clock.currTime();
   writeln("Aujourd'hui : ", auj.day, " ", auj.month, " ", 
auj.year);
   writeln("Le d├ębut : ", deb.day, " ", deb.month, " ", deb.year);

   Duration diff = cast(DateTime) auj - deb;
   auto ecart = diff.total!"days" + 1;
   writeln("Diff : ", diff.total!"days" + 1);
   writeln(ecart);
}

Thanks for replies...
Nov 13 2019
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 13 November 2019 at 17:23:42 UTC, Mil58 wrote:
 In the following example, i would to add the "diff" value (in 
 days) to a certain date (or the today's date "auj") >>
just use the plus operator auto newTime = Clock.currTime() + 5.days
Nov 13 2019