Re: [Zope] How to subtract one date from another?
in article list.apps.zope/390724DA.A584F61B@cat-box.net, Steve Alexander at steve@cat-box.net wrote on 2000-04-26 1:18 PM:
<dtml-var "_.int(_.round(date2-date1))"> gives you the number of days as a rounded integer. (That is, half days get counted as a whole day).
This is awesome-- I was just struggling with this problem. I wanted to do the exact same thing. One big problem with Zope is that its so easy to do these things, but _so_ hard to figure out the syntax to do it! Here is my contribution. I create a date attribute called targetdate that people modify. I want to have a simple integer on a page showing how many days from _now_ till that 'target date.' Here is my snipped that works: (thanks to the previous posts) <dtml-let now="ZopeTime()"> <dtml-let due="targetdate"> <b><dtml-var "_.int(_.round(due-now))"></b> </dtml-let></dtml-let> -andy diller
Andrew Diller wrote:
Here is my contribution. I create a date attribute called targetdate that people modify. I want to have a simple integer on a page showing how many days from _now_ till that 'target date.'
Here is my snipped that works: (thanks to the previous posts)
<dtml-let now="ZopeTime()"> <dtml-let due="targetdate"> <b><dtml-var "_.int(_.round(due-now))"></b> </dtml-let></dtml-let>
One caveat here: the rounding won't be correct if you have anything to do with daylight-savings time in your machine's timezone, or in the time you're storing. It will most likely be an hour out. See other posts to the list about problems with DateTime and daylight savings. -- Steve Alexander Software Engineer Cat-Box limited
participants (2)
-
Andrew Diller -
Steve Alexander