Changing Date Format

I have a form with a date input ($invoicedate)

when i echo $invoicedate on my page it returns for example 2020-06-08

how do i format this to show 06-08-2020 as in day month year ?

Thanks

You can convert the string to a DateTime object DateTime::createFromFormat:

$invoice_dt = DateTime::createFromFormat('Y-m-d', $invoicedate);

Then create a string with your new format using DateTime::format:

$reformated_invoice_date = $invoice_dt->format('d-m-Y');
1 Like

excellent thank you for your advice

if i have this code how do i alter thisto show day month year ?

echo “” .$row[“MILEAGEDATE”]. "

MILEAGTDATE is the name of the row in my database ?

its ok i sorted it thanks

Sponsor our Newsletter | Privacy Policy | Terms of Service