aide2001 Posted July 14, 2020 Share Posted July 14, 2020 Hi people I have some code to retireve dates from a database, see below. The issue is i can not find a way to change the output to d,m,Y instead of what the data comes back from database. Any help with this would be much appriciated. The transaction date is getting the invoice date created back as 2020-04-01 etc, but how to swap this code?, I dont think i can do it within the array. $statement_transactions = array(); $client_total_balance = $client_opening_balance; foreach ($client_invoices as $invoice_entry) { $transaction = [ 'transaction_type' => self::TRANSACTION_TYPE_INVOICE, 'transaction_date' => $invoice_entry->invoice_date_created, 'transaction_amount' => $invoice_entry->invoice_total, 'invoice_id' => $invoice_entry->invoice_id, 'client_id' => $invoice_entry->client_id, 'user_company' => $invoice_entry->user_company, 'invoice_amount_id' => $invoice_entry->invoice_amount_id, 'invoice_item_subtotal' => $invoice_entry->invoice_item_subtotal, 'invoice_item_tax_total' => $invoice_entry->invoice_item_tax_total, 'invoice_total' => $invoice_entry->invoice_total, 'invoice_sign' => $invoice_entry->invoice_sign, 'invoice_status_id' => $invoice_entry->invoice_status_id, 'invoice_date_created' => $invoice_entry->invoice_date_created, 'invoice_time_created' => $invoice_entry->invoice_time_created, 'invoice_number' => $invoice_entry->invoice_number, ]; $client_total_balance += $invoice_entry->invoice_total; $statement_transactions[] = $transaction; } Quote Link to comment https://forums.phpfreaks.com/topic/311082-php-code-for-date-retrival-from-database/ Share on other sites More sharing options...
Barand Posted July 14, 2020 Share Posted July 14, 2020 You have a couple of options 1 ) Re-format the date in the SQL query when you retrieve the records. EG SELECT DATE_FORMAT(invoice_date_created, '%d.%m.%Y') as invoice_date_created 2 ) Re-format after retrieval in the array $transaction['invoice_date_created'] = date('d.m.Y', strtotime($transaction['invoice_date_created'])); Quote Link to comment https://forums.phpfreaks.com/topic/311082-php-code-for-date-retrival-from-database/#findComment-1579611 Share on other sites More sharing options...
aide2001 Posted July 14, 2020 Author Share Posted July 14, 2020 Many thanks for this information. I'm unable to change the format when retrieving from database as this isnt my code, its from a template system and do not know how this is being queried. I have tried changing this re-format after retrieval in the array, and im still as yet to figure that out, everytime i try the code above it comes up with - Call to a member function format() on boolean which i think is the date. Might have to rethink how to proceed. Quote Link to comment https://forums.phpfreaks.com/topic/311082-php-code-for-date-retrival-from-database/#findComment-1579613 Share on other sites More sharing options...
Barand Posted July 14, 2020 Share Posted July 14, 2020 Post the code that's giving the problem. We are not clairvoyant. Quote Link to comment https://forums.phpfreaks.com/topic/311082-php-code-for-date-retrival-from-database/#findComment-1579619 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.