-1

This is my function i want to change my date format

like this m/d/y

foreach ($totals as $item => $val) {
            $result['totals_labels'][] = $item;
            $result['totals_values'][] = $val;
            $result['details_labels'][] = $item;
            $totals['date'] = date("m/d/Y",strtotime($totals['date'])).'<br/>'; 
            print_r($totals['date']);
        }
        $result['details'] = $data;

        print_r($result);
                exit();

print_r($totals['date']); Response

07/19/5801
12/31/1969
12/31/1969
12/31/1969
12/31/1969
12/31/1969
12/31/1969
Array

print_r($result['details']) Response

[total] => 500
                    [good] => 401
                    [bad] => 99
                    [duration] => 4.67320
                    [percentGood] => 80.2
                    [date] => 1521086400
                    [time] => 1521086400
                    [peak] => 401

in Date format not changing into $result['details'] response

Learning
  • 79
  • 1
  • 7

2 Answers2

2

Use Strtotime. it Parse about any English textual datetime description into a Unix timestamp

Change From

date("m/d/Y",$totals['date']); 

To

date("m/d/Y",strtotime($totals['date'])); 
TarangP
  • 2,711
  • 5
  • 20
  • 41
0
 <?php
   $date=date_create("2018-03-15");
   echo date_format($date,"m/d/y H:i:s");
  ?>

date_format() method returns a date formatted according to the specified format.

Adil kp
  • 83
  • 3
  • 8