Page 2 of 2

Re: Dates - Last Sunday of the month

Posted: Wed Sep 09, 2009 6:37 am
by Darhazer
Here is recent example. The code is from some version of smarty, which worked quite well:

Code: Select all

function smarty_make_timestamp($string)
{
    $time = strtotime($string);
    if (is_numeric($time) && $time != -1)
        return $time;
 
    // is mysql timestamp format of YYYYMMDDHHMMSS?
    if (is_numeric($string) && strlen($string) == 14) {
        $time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2),
               substr($string,4,2),substr($string,6,2),substr($string,0,4));
 
        return $time;
    }
 
    // can decipher, must be timestamp already?
    return $string;
}
Local machine:

Code: Select all

$ php --version
PHP 5.2.9 (cli) (built: Apr 17 2009 03:42:25) 
$php -r "var_dump(strtotime( 1252609023 ));"
bool(false)
 
Old server:

Code: Select all

php -v
PHP 4.3.2 (cgi)
$ php -f test.php 
int(-1)
New server, doesn't work correctly:

Code: Select all

# php --version
PHP 5.2.8 (cli) (built: Aug 11 2009 17:57:58) 
#php -r "var_dump(strtotime( 1252609023 ));"
int(222592906380)