1

I tried a few things and so far and no success.

I want to make dates that are yyyy-mm-dd look like mm/dd/yyyy

Initial value example, taken from MySQL: 2015-08-21 14:46:00

Here's what I got:

foreach ($draftOrders as $key => $value) {
    $timestamp = strtotime($value['last_modified']);

    // this one works (leaving it unchanged)
    // however the slashes are not replacing the dash
    // $new_date_format = date('Y/m/d H:i:s', $timestamp);

    // fails, date becomes 1970-01-01 12:00 am
    $new_date_format = date('m/d/Y H:i:s', $timestamp);
    $draftOrders[$key]['last_modified'] = $new_date_format;
}
jSmith
  • 275
  • 1
  • 4
  • 13

2 Answers2

1

To perform that sort of date formatting in mysql you might want to look at the following:-

select date_format(`date`,'%Y/%m/%e %H:%i:%s') from `table`
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
0

try this

 echo date('m/j/Y', strtotime('2015-08-21 14:46:00'));

http://php.net/manual/en/function.date.php

badr aldeen
  • 448
  • 7
  • 22