I am reading in a csv file and one of the fields contains a date in the format dd/mm/yyyy, however, on the first nine days it is d/mm/yyyy.
I have used sc_date_conv to try and code it to the db_format and the code works fine until those first 9 days of the month and then I get errors - the dates being added to the INSERT INTO string go haywire.
Is this a bug in SC or should I be using a conditional statement based on the day of the month, or what?
I have placed my code below, but to summarize 10/04/2015 works but 9/04/2015 does not.
Thanks
Tony
Code under the “import” button.
$cnt=0;
$handle = fopen({csv_file}, ‘r’);
if ($handle)
{
set_time_limit(0);
//loop through one row at a time
while (($data = fgetcsv($handle, 4096, ‘,’)) !== FALSE)
{
$_date = sc_date_conv($data[0],“dd/mm/YYYY”,“db_format”);
$_amount = ABS($data[1]);
$_payee = $data[2];
if ($data[1] < 0) {
$_drcr = 1;
}else{
$_drcr = -1;
}
$_bank = {bank_code};
if ($data[1] < 0) {
$_type = 1;
}else{
$_type = 0;
}
$_not_balanced = 1;
$stm =“INSERT INTO transactions (tr_date,tr_amount,tr_payee,tr_drcr,tr_bank,tr_type,tr_not_balanced)
VALUES (’{$_date}’,{$_amount},’{$_payee}’,{$_drcr},{$_bank},{$_type},{$_not_balanced})”;
sc_exec_sql($stm);
$cnt++;
}
fclose($handle);
}