This question about Using an extension: Closed unanswered

How can I compare dates in if and query statements?

I desperately try to compare two dates in an IF - statement to achieve an action accordingly, wheras one is in a variable.

Used time fomat in variable is "22 Apr 2013"

Variable is called %DATUM% and is defined by using a date stored in a meta preference data

Now I try to get a result depending if a date is in a certain timeframe.

Example: if %DATUM% is between now and the next two days I want to get result A

%IF{"' '%DATUM%' > now AND 'now + 2*86400' " then="A"}%

86400 is one day in seconds

I tried many things using CALC, d2n and combinations of these. What surprisingly works is

%IF{"' '%DATUM%' > now " then="A"}%

If somebody could resolve this issue I would be very happy.

-- ThomasSchmidt - 23 Apr 2013

  • Set DATUM1 = 23 Apr 2013
  • Set DATUM2 = 24 Apr 2013
  • Set DATUM3 = 25 Apr 2013
  • Set DATUM4 = 26 Apr 2013

While that may not be perfect (view wiki text for details), I hope it points you in the right direction.

I think your final 'working' example is in fact broken.

-- JulianLevens - 23 Apr 2013

Thx, but It doesn't work. I use it within DBQuery format string such as:

%IF{"d2n('$expand(preferences.due)') > d2n('%DATE%') AND d2n('$expand(preferences.due)') <= %CALC{"$TIMEADD($TIME(),2,day)"}%" then="A"}%

while due is a META::PREFERENCE variable

Maybe it is a matter of how DBQUERY works.

Still amazing is that when I use %IF{"'$expand(preferences.due)' > d2n('%DATE%') then="A"}%

It Works!

-- ThomasSchmidt - 23 Apr 2013

Sorry but I don't have a quick answer, and I don't know DBQUERY.

I do wonder if embedding %IF inside a %DBQUERY might be an issue. I'm not sure if %IF understands $expand even though DBQUERY does.

-- JulianLevens - 23 Apr 2013
 

QuestionForm edit

Subject Using an extension
Extension DBCachePlugin
Version Foswiki 1.1.8
Status Closed unanswered
Related Topics
Topic revision: r5 - 24 Apr 2013, ThomasSchmidt
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy