1

I have a field within a MySQL database that has a date format of the following:

Mon, 17 Aug 2015 19:14:22 +0100

I want to display this date using PHP in the following format:

YYYY-MM-DD HH:MM:SS

I have no idea how to pick out the different elements and reformat them.

Can somebody help?

Many thanks,

John

John Higgins
  • 857
  • 12
  • 25

2 Answers2

2

You can try these :-

$date    = "Mon, 17 Aug 2015 19:14:22 +0100";
$newDate = date('Y-m-d H:i:s', strtotime($date));

echo $newDate;
Harsh Sanghani
  • 1,666
  • 1
  • 14
  • 32
1

You can do it in mysql

SELECT 
  DATE_FORMAT(test.dateFrom, '%Y-%M-%d %H:%i:%s') as date,
FROM test

Or in php

$date = date('Y-m-d H:i:s', strtotime($datefrommysql) );
Gumma Mocciaro
  • 1,205
  • 10
  • 24