Just another Perl shrine PerlMonks

### Re: Re: Re: Date difference?

by jlongino (Parson)
 on Apr 29, 2002 at 02:38 UTC ( #162749=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Date difference?

This is explained in  perldoc Date::Calc
```* "(\$Dd,\$Dh,\$Dm,\$Ds) = Delta_DHMS(\$year1,\$month1,\$day1,
\$hour1,\$min1,\$sec1, \$year2,\$month2,\$day2, \$hour2,\$min2,\$sec2);"

This function returns the difference in days, hours, minutes and
seconds between the two given dates with times.

All four return values will be positive if the two dates are in
chronological order, i.e., if date #1 comes chronologically BEFORE
date #2, and negative (in all four return values!) if the order of t
+he
two dates is reversed.

This is so that the two functions ""Delta_DHMS()"" and
""Add_Delta_DHMS()"" (description see further below) are
complementary, i.e., mutually inverse:

+me2))

yields ""(@date2,@time2)"" again, whereas

map(-\$_, Delta_DHMS(@date1,@time1, @date2,@time2)))

yields ""(@date1,@time1)"", and

yields ""@delta"" again.

The result is zero (in all four return values) if the two dates and
times are identical.

--Jim

Replies are listed 'Best First'.
Re: Re: Re: Re: Date difference?
by chicks (Scribe) on Apr 29, 2002 at 03:07 UTC
I know it's explained in the docs, but it still seems counterintuitive.
Perhaps it will make more sense if you play with the code examples they give after explaining that they want functions Delta_DHMS() and Add_Delta_DHMS() to be complementary/mutually inverse.

It seems intuitive to me, particularly if you were going to use the positive/negative results as arguments in a followup function call.

--Jim

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://162749]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2021-11-28 17:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?