Differences between two dates (in days...)

Daniel Kozak kozzi11 at gmail.com
Thu Oct 24 12:08:33 UTC 2019


On Thu, Oct 24, 2019 at 1:55 PM Mil58 via Digitalmars-d-learn
<digitalmars-d-learn at puremagic.com> wrote:
>
> Hi All...
> I am desperate for the answer to the following problem:
> to obtain the difference between the date of today and an older
> date (results in days...)
>
> See my script below, where I would like to do:
> "date of today" (var: auj) - "an older date" (var: deb) = xx days
>
> 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);
> }
>
> Thanks in advance !  :-)

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);
writeln("Diff in days : ", (cast(DateTime)auj - deb).total!"days");
}



More information about the Digitalmars-d-learn mailing list