Jump to content

Recommended Posts

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;

        }

 

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']));

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.