-2

I am trying to convert a javascript date object in php. I have tried to convert using my posted code, but it puts the time as 12:00:00. The date is being sent as 'Mon May 15 2017 15:08:03 GMT 0100 (GMT Standard Time)'. The idea is to insert into mysql in the format yyyy-mm-dd.

I would appreciate any help with this as it's driving me nuts. Many thanks.

UPDATE: I need the date & the time.

$intakedate = $_GET['date'];

$intakedateString = $intakedate;
$intakedateParts = explode(' ', $intakedateString, 5);
$intakedatenew =  date('Y-m-d h:i:s', strtotime($intakedateParts[2] .  ' '  . $intakedateParts[1] . ' '  . $intakedateParts[3]));
user1532468
  • 1,723
  • 8
  • 41
  • 80

1 Answers1

2

Try this code :

<?php
$date = new DateTime('Mon May 15 2017 15:08:03');
echo $date->format('Y-m-d');

?>
Rahul
  • 2,374
  • 2
  • 9
  • 17
  • I need the date & time to post to mysql. Thanks – user1532468 May 31 '17 at 08:40
  • Throws this error: [31-May-2017 08:45:43 UTC] PHP Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [datetime.--construct]: Failed to parse time string (Mon May 15 2017 15:08:03 GMT 0100 (GMT Standard Time)) at position 39 (S): Double timezone specification' in C:\wamp\www\domain\admin\data.php:35 Stack trace: #0 C:\wamp\www\domain\admin\data.php(35): DateTime->__construct('Mon May 15 2017...') #1 {main} thrown in C:\wamp\www\domain\admin\data.php on line 35 – user1532468 May 31 '17 at 08:47