anyone know a quick way to compare two date strings without having to complete tear the string apart? thanks, kyle
Kyle Burnett wrote:
anyone know a quick way to compare two date strings without having to complete tear the string apart?
Use the DateTime Object, in python: Py$ from DateTime import DateTime Py$ DateTime() > DateTime('Jan 1, 1999') 1 Py$ in DTML: <dtml-if "_.DateTime() > _.DateTime('Jan 1, 1999')"> True. </dtml-else> You should never see this unless the universe reversed itself. </dtml-if> Calling the DateTime object with no arguments means 'now'. It accepts a number of different date formats. I just made this one up and it happily accepted it. In DTML, _.DateTime is synonymous with the global value ZopeTime. So the Second example is equivalent to: <dtml-if "ZopeTime() > ZopeTime('Jan 1, 1999')"> True. </dtml-else> You should never see this unless the universe reversed itself. </dtml-if> -Michel
Michel Pelletier wrote:
Kyle Burnett wrote:
anyone know a quick way to compare two date strings without having to complete tear the string apart?
Use the DateTime Object, in python:
Py$ from DateTime import DateTime Py$ DateTime() > DateTime('Jan 1, 1999') 1 Py$
in DTML:
<dtml-if "_.DateTime() > _.DateTime('Jan 1, 1999')"> True. </dtml-else> You should never see this unless the universe reversed itself. </dtml-if>
Yeah ;) But whats with comparing wether we are between hour xx and hour yy every day? Or even between 0:00 and 1:15 every day... This comes up with very strange hassle with DateTime() and strings and int() and so on... Or is there a better way? Best regards Tino Wildenhain
Tino Wildenhain wrote:
Yeah ;) But whats with comparing wether we are between hour xx and hour yy every day? Or even between 0:00 and 1:15 every day...
DateTime works at one one-thousandth of a second resolution. Hours and minutes are no problem.
This comes up with very strange hassle with DateTime() and strings and int() and so on...
No hassle that I can see, no more so than any other kind of object that would do this.
Or is there a better way?
There's mxDateTime, which I believe works similarly to DateTime. I don't think one is any 'better' than the other. -Michel
participants (3)
-
Kyle Burnett -
Michel Pelletier -
Tino Wildenhain