last day (14 days later) » 

11:34 AM
2
A: DateTime format in PHP

DaanOne method is to use the datetime class: $dateTime = new DateTime($yourDateTimeVariable); $dateTime = $dateTime->format('Y-m-d H:i'); echo $dateTime;

 
By adding my variable it shows current time not my variable.
 
Can you copy/paste the code you have right now?
 
Is there possible to post variable using POST method?
 
Yes sure of course you can.
 
$dateTime = new DateTime('".$_POST["datetimepicker"]."'); $dateTime = $dateTime->format('Y-m-d H:i'); echo $dateTime; Something like this?
 
11:34 AM
Change: new DateTime('".$_POST["datetimepicker"]."'); to: new DateTime($_POST["datetimepicker"]);
 
Fatal error: Call to a member function format() on a non-object
 
What is in $_POST['datetimepicker']? And can you post your code one more time ?
 
Here is example of my datetime picker jsfiddle.net/ZiNNED/4fa5n7wa/18
if i'm not selecting any value it prints Tue Dec 09 2014 12:00:00 GMT+0200 (FLE Standard Time)
 
What happens when you var_dump($dateTime); after creating an instance
 
sorry, i didn't get it?
Now what I'm trying to do:

$datep = ".$_POST["datetimepicker3"].";


$dateTime = new DateTime($datep);
$dateTime = $dateTime->format('Y-m-d H:i');
echo $dateTime;
but it posts current time
Now the error i get: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (Tue Dec 09 2014 12:00:00 GMT+0200 (FLE Standard Time)) at position 39 (S): Double timezone specification
Using your offered option: Fatal error: Call to a member function format() on a non-object
 

last day (14 days later) »