Re: newbie date time question

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

 



On 23/06/11 10:04 AM, Shawn McKenzie wrote:
On 06/22/2011 06:54 PM, David Nicholls wrote:
I'm late to the party, but strtotime works great, though you need to
give it what it expects:

$ts = strtotime(str_replace('/', '-', $date));


Thanks, Shawn, that's a bit more elegant!  I'll give it a go. I didn't
know how to do the str_relace bit.  Thanks

The deal is that if you use the / then strtotime interprets it as m/d/y
and if you use - it interprets it as d-m-y.



Yes, I knew the '-' format would work, I just didn't know quite how to convert the '/' to '-'. A very simple and clean solution.

The final form is:

function read_data($filename)
{
    $f = fopen($filename, 'r');
    while ($d = fgetcsv($f)) {
    $ts = strtotime(str_replace('/','-',$d[0]));
    $data[] = array($ts, $d[1]);
    }
    fclose($f);
    return $data;
}

DN

--
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