I read a csv file like this one :
391;WETSUITS;07/07/2020 12:47:36;0021000001463;
392;WETSUITS;07/07/2020 12:47:49;0021000007845;
....
I retrieve the one date with this format :
echo $data[2] = 07/07/2020 12:47:36
I would like to have two variables :
$date = 07-07-2020 or 2020-07-07
$time = 1247
I tried with str_replace for the first part but I get "Notice: Undefined offset: 2" as an error message, how can I change this?
<?php
$csv = 'C:/wamp64/www/BI/BI1_20200707_1520_28044.csv';
if (($handle = fopen("$csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 9000000, ";")) !== FALSE){
// echo $data[2]; //07/07/2020 12:47:36
$new = str_replace('/', '_', $data[2]);
echo $date = substr($new,0,20)."\n";;
}
}
?>