Zaz
Zaz

Reputation: 1102

PHP: Problems using strtotime

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'])

Upvotes: 0

Views: 79

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324790

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();
}

Upvotes: 1

Related Questions