0

I want to filter my output:

07-02-13 20:08:41   [email protected]
07-02-13 20:09:41   [email protected]
07-02-13 20:21:25   [email protected]
07-02-13 20:56:51   [email protected]
07-02-13 21:42:37   [email protected]
07-02-13 22:09:11   [email protected]

I want to filter my output, so emails there appearing within 2 minutes has to do something. This is my "filter code" so far. But it is not working. What am i doing wrong?

strtotime('-2 minutes"', strtotime(date('d-m-y H:i:s', $filter['created'])
2
  • What is $filter['created']? If it contains timestamp, why are you formating it to ambigous date fromat just to turn it back into timestamp and substract 2 minutes? What is not working? Code you posted does not attempt to filter anything... Commented Feb 7, 2013 at 23:37
  • I was having trouble with this as well. I was taking a date in the format of MM-DD-YYYY and I created a function [ that I called rolex() :) ] and this used strtotime to get a unix timestamp that I used to remove the 0s from the front of the MM and DD [ date('n-j-Y', $d_string); ]... Commented Feb 7, 2013 at 23:51

1 Answer 1

1

The problem is that you date format is ambiguous. Does 07-02-13 mean February 7th 2013 (ie today) or does it mean July 2nd 2013 (US standard format), or does it mean February 13th 2007 (big-endian format) or what?

I would suggest rewriting your code so that it produces timestamps in big-endian format,
that is Y-m-d H:i:s. In this format, you can compare them as if they were strings, so all you'd have to do is:

$two_minutes_ago = date("Y-m-d H:i:s",strtotime("-2 minutes"));
if( $value_to_test > $two_mintes_ago) {
    do_something();
}
Sign up to request clarification or add additional context in comments.

1 Comment

I tried your way, but it did not work. Is not filtering what I posted on top

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.