php-general Digest 22 Jun 2011 14:15:31 -0000 Issue 7370

Topics (messages 313635 through 313635):

newbie date time question
        313635 by: David Nicholls

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
I'm trying to convert a date and time string using strtotime()

The date and time strings are the first entry in each line in a csv file in the form:

22/06/2011 9:47:20 PM, data1, data2,...

I've been trying to use the following approach, without success:

function read_data($filename)
{
    $f = fopen($filename, 'r');
    while ($d = fgetcsv($f)) {

        $format = 'd/m/Y h:i:s';
        $dt = DateTime::createFromFormat($format, $d[0]);

        $data[] = array(strtotime($dt), $d[1]); //convert date/time
    }
    fclose($f);
    return $data;
}

Obviously I'm not getting the $format line right, as the resulting $dt values are empty. (I have previously used this reading process successfully with better behaved date and time strings).

Advice appreciated.

DN

--- End Message ---

Reply via email to