0

how can i modify the code below to output a date in the the format d-m-Y H:i:s

public function storeFormValues($params)
{

    // Store all the parameters
    $this->__construct($params);

    // Parse and store the publication date
    if (isset($params['publicationDate'])) {
        $publicationDate = explode('-', $params['publicationDate']);

        if (count($publicationDate) == 3) {
            list($y, $m, $d) = $publicationDate;
            $this->publicationDate = mktime(0, 0, 0, $m, $d, $y);
        }
    }
}`
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • 1
    I can't see "H:i:s" in the code. – Andreas Dec 23 '20 at 12:56
  • Does this answer your question? [Convert one date format into another in PHP](https://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – Dharman Dec 23 '20 at 14:32

1 Answers1

0

You can do it simply like this

public function storeFormValues($params)
{

    // Store all the parameters
    $this->__construct($params);

    // Parse and store the publication date
    if (isset($params['publicationDate'])){
        $d = new DateTime($params['publicationDate']);
        echo $d->format('d-m-Y H:i:s');
        }
}
M Umer Yasin
  • 284
  • 3
  • 6