[pmwiki-users] How to: calculate how many days left
Patrick R. Michaud
pmichaud at pobox.com
Wed Feb 27 11:52:32 CST 2008
On Wed, Feb 27, 2008 at 11:29:02AM -0600, Patrick R. Michaud wrote:
> Thus we have:
>
> {(div (sub (ftime %s {$:Date}) (ftime %s today)) 86400)}
>
> One should note that both this and the udays approach have a
> potential problem if the range of dates span changes in daylight
> savings time. In this case the difference will not be an even
> multiple of 86400, and using floor() will provide an incorrect
> value.
>
> A way to avoid this would be to use ftime itself to determine
> the number of days (this works up to 365 days):
>
> {(ftime %d (sub (ftime %s {$:Date}) (ftime %s today)))
Oh, thinking about this a bit more, this would suffer
from the same problem with daylight savings time also.
So we're back to:
{(div (sub (ftime %s {$:Date}) (ftime %s today)) 86400)}
and simply recognize that it may report fractional values
whenever the range includes a change due to daylight savings time.
Pm
More information about the pmwiki-users
mailing list