Re: newbie date time question

From: Date: Thu, 23 Jun 2011 00:40:33 +0000
Subject: Re: newbie date time question
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-313673@lists.php.net to get a copy of this message
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

« previous php.general (#313673) next »