-1

I got an output like this, I am doing it in php :

Tue Jul 12 09:48:44 2016

I want to convert it into like this :

2016-07-12 09:48:44
Marcin
  • 7,834
  • 8
  • 52
  • 99
minu
  • 73
  • 2
  • 2
  • 9

3 Answers3

2

Use date() function to change date time format and don’t forget to use strtotime()

date ("Y-m-d h:i:s",strtotime("Tue Jul 12 09:48:44 2016"))
Dhara Parmar
  • 8,021
  • 1
  • 16
  • 27
0

You can try the below code

$date = 'Tue Jul 12 09:48:44 2016';
echo date('Y-m-d H:i:s',strtotime($date));

Output: 2016-07-12 09:48:44

Arun
  • 3,640
  • 7
  • 44
  • 87
0

I'd parse the input with createFromFormat:-

$dateInputString = "Tue Jul 12 09:48:44 2016";

//Convert the string from the format supplied to a date
$date = DateTime::createFromFormat('D M d H:i:s Y', $dateInputString);

//output the date in the required format
echo $date->format('Y-m-d H:i:s');
Ian White
  • 11
  • 3