Re: newbie date time question
| From: | David Nicholls | Date: | Wed, 22 Jun 2011 23:54:54 +0000 |
| Subject: | Re: newbie date time question | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313669@lists.php.net to get a copy of this message | ||
On 23/06/11 1:35 AM, Shawn McKenzie wrote:
On 06/22/2011 09:05 AM, David Nicholls wrote: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 DNI'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) {I'm late to the party, but strtotime works great, though you need to give it what it expects: $ts = strtotime(str_replace('/', '-', $date));$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