Re: Basic Dual Query Combine into one question
| From: | Christoph Becker | Date: | Fri, 06 Feb 2015 16:19:03 +0000 |
| Subject: | Re: Basic Dual Query Combine into one question | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324403@lists.php.net to get a copy of this message | ||
dealTek wrote:
> function cmp($a, $b)
> {
> $result = strcmp(
>
> // !!!!!! errors ???? how do I fix?
> $a->strtotime(getField('Test_Date')),
> $b->strtotime(getField('Test_Date'))
> );
Others have already pointed out that strtotime() is a function and not a
method. I suggest that you learn the basics of object oriented
programming in PHP[2], even if you don't plan to write your own classes.
Furthermore it seems to be noteworthy that strtotime() parses strings in
the format 01/02/2015 as American dates, i.e. as Jan. 2, 2015.[1] If
you have to deal with European dates (d/m/Y), you would have to prepare
the date string before passing it to strtotime().
Regarding the sorting: you don't want to to strcmp() the results of
strtotime(), because the results are numbers. The simplest and most
efficient solution is to subtract these numbers:
$result = strtotime($a->getField('Test_Date'))
- strtotime($b->getField('Test_Date'));
[1] <http://php.net/manual/en/language.oop5.php>
[2]
<http://php.net/manual/en/function.strtotime.php#refsect1-function.strtotime-notes>
--
Christoph M. Becker