-4

how can I format datetime in php from: Tue Dec 09 2014 12:00:00 GMT+0200 (FLE Standard Time) to: 2014-12-09 12:00?

Thank you.

Problem solved. I did it by myself:

$datep = $_POST["datetimepicker"];
$placeholders = array('(FLE', 'Standard', 'Time)');
$vals = array('', '', '');
$str = str_replace($placeholders, $vals, $datep);
$newDate = date('Y/m/d H:i', strtotime($str));
echo $newDate;
Xinel
  • 119
  • 13
  • You need to look at the documentation for PHP. Do you know where to find it? =] – Relequestual Dec 08 '14 at 11:27
  • I'm not as dumb as you think :) – Xinel Dec 08 '14 at 13:08
  • The reason people have downvoted your question is because you didn't explain what you had tried so far, or explain you've looked at the docs but still didn't understand. If you don't fully explain yourself, people will think you genuinly don't know where the docs are =p – Relequestual Dec 08 '14 at 13:38

3 Answers3

2

One method is to use the datetime class:

$dateTime = new DateTime($yourDateTimeVariable);
$dateTime = $dateTime->format('Y-m-d H:i');
echo $dateTime;
Daan
  • 12,099
  • 6
  • 34
  • 51
1

Try this -

$date = "Tue Dec 09 2014 12:00:00 GMT+0200";
$newDate = date('Y-m-d H:i', strtotime($date));
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
0

You can use strototime combined with date. Something like

$date = "Tue Dec 09 2014 12:00:00 GMT+0200 (FLE Standard Time)";

$format = date("Y-m-d H:i", strtotime($date));
Erik Terwan
  • 2,710
  • 19
  • 28