Search

“on or before” and “on or after”?

“on or earlier than” keeps the use of “earlier than” that the current code uses, and it’s quite concise. That’d have my vote :)

How strange that I was working with the same thing just a few hours ago.

I ended up making earlier-inc/later-inc.

In the DS filtering it was then: earlier-inc than {$today}-{$current-time}.

I have just run into another ‘wall’. Trying to get entries that are ‘recent’ ie. 7 days ago onwards…

To answer my own question:

{$today} - 7 days

Gets all entries from 7 days ago onwards.

The DS Filtering for date seems to use strtotime so most of it’s shortcuts should work..

Did anyone implement an update in the source for ‘less/more than or equal to”?

I made this change myself, with a large amount of help from Arood on IRC :)

elseif(preg_match('/^(equal to or )?(earlier|later) than (.*)$/i', $string, $match)){

            $string = $match[3];

            if(!self::__isValidDateString($string)) return self::ERROR; 

            $time = strtotime($string);
            if($match[1] == "equal to or "){
                $later = DateTimeObj::get('Y-m-d H:i:s', $time);
                $earlier = $later;              
            }
            else {
                $later = DateTimeObj::get('Y-m-d H:i:s', $time+1);
                $earlier = DateTimeObj::get('Y-m-d H:i:s', $time-1);
            }
            switch($match[2]){
                case 'later': $string = $later . ' to 2038-01-01'; break;
                case 'earlier': $string = '1970-01-03 to ' . $earlier; break;
            }

        }

I’ve submitted the change to Github, but feel free to rewrite it if there’s a neater way to do it.

Is there a case for this to be added to the core?

I spent the last day figuring out why I wasn’t seeing any results after upgrading to 2.0.6 and realised that edits to the core Lib were made and overwritten by the upgrade.. the above was added to GIT but not included.. and was wondering if the change is solid enough to include in future updates?

Is there a case for this to be added to the core?

We’ll discuss it for a post-2.0.7 release.

@brendo - I tried your solution in comment #24 in 2.0.8 RC1 and RC3 (I guess it’s the same in 2.0.7).

{$today} - 7 days

Gets all entries from 7 days ago onwards.

The DS Filtering for date seems to use strtotime so most of it’s shortcuts should work…

Unfortunately, that doesn’t work, but since it looks as if the earlier than and later than wording was added in as of 2.0.7, you CAN achieve the last 7 days (not including the current day) like so…

later than {-7 days} + earlier than {$today}

Or if you would like to do the last 7 days including today’s date, you would achieve it this way.

later than {-7 days} + earlier than {0 days}

You might be saying, well aren’t those the same? {$today} and {0 days}… well, actually they are not… I’m not sure why… but it works.

{0 days} works to include today’s date when you say earlier than {0 days}

@bzerangue: This is an interesting observation! I have double-checked this. So:

earlier than {$today}  :  earlier than today (excluding today)
earlier than {0 days}  :  earlier than or equal to today

But these two show the same result:

1971-01-01 to {$today}  :  from ... to today (including today)
1971-01-01 to {0 days}  :  from ... to today (including today)

An so do these:

later than {$today}  :  later than or equal to today
later than {0 days}  :  later than or equal to today

Hmmm, there are some questions left to me:

  • Why do the earlier than examples (#1) show different results?
  • Why do the later than examples (#3) show the same result?
  • Why does the result in the later than examples (#3) include today?

I’d love to know if this is intended. If there are bugs, they should of course not be fixed without prominent information (because many websites rely on the filters working like this, probably).

[EDIT]: Everything was tested on Symphony 2.0.7.

Examples,

if you want to find all entries from the previous day you would get it by filtering your data source like so…

later than {-2 days} + earlier than {$today}

if you want to find all entries from the previous week you would get it by filtering your data source like so…

later than {-1 weeks} + earlier than {0 weeks}

if you want to find all entries from the previous month you would get it by filtering your data source like so…

later than {-2 months} + earlier than {-1 month}

if you want to find all the entries just for the previous year, you can get it by…

later than {-2 years} + earlier than {-1 year}

EDIT: Added the following on February 21, 2011

if you want to find all the entries today and earlier, you can get it by…

earlier than {$today}, {$today}

Nick mentions a parameter of $now in a previous comment, which was exactly what I was looking for to use in some datasource filters, unfortunately it doesn’t seem to exist (I’m not sure if it previously did and was removed?).

It can be hacked into existance by adding it into the build of the default parameters in the core FrontendPage class (@ symphony/lib/toolkit/class.frontendpage.php):

'now' => DateTimeObj::get('Y-m-d H:i:s')

In my case appending the current-time to today wasn’t good enough as I also needed the seconds.

Could someone help clarify how to get all entries for today (The current day) and all future entries?

later than {$today}, {$today}
later than yesterday

Nice and short :) cheers

Or try this:

equal to or later than today

See: https://github.com/symphonycms/symphony-2/wiki/DateField.

And keep in mind that the current version of the core date field supports all relative dates from PHP's own DateTime function. Things like "today +2 days" etc. (no curly braces needed).

Ahh I did not know that Nils :) I've been using {$today} for ages.

Well, it works with {$today} as well – but it's no longer needed.

But be aware that you have to url-encode characters with special meaning in datasource filtering. Like '+' should be '%2B'.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details