Re: Basic Dual Query Combine into one question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux