[pmwiki-users] How to: calculate how many days left
Patrick R. Michaud
pmichaud at pobox.com
Wed Feb 27 11:29:02 CST 2008
On Wed, Feb 27, 2008 at 04:51:42PM +0000, Hans wrote:
> Wednesday, February 27, 2008, 4:20:14 PM, Patrick R. Michaud wrote:
> >> 3) Using " {(sub (udays {$:Date}) (udays now) )} " in wiki pages to
> >> get number of how many days left.
>
> > Simpler might be
>
> > {(div (sub (ftime %s {$:Date}) (ftime %s)) 86400)}
>
> (ftime %s) is the unix time value for
> Now, and not previous midnight, so the div above will have a fraction
> part.
Ah. One can use (ftime %s today) to get the previous midnight.
One can also use (ftime %s tomorrow) to get the next midnight.
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)))
Pm
More information about the pmwiki-users
mailing list