I have a php string which contains the date and time as shown below
2015-05-27 18:45:31
How can I convert this to a type which I can insert into postgresql table with timestamp data type?
Convert it using strtotime() function:
$unix_timestamp=strtotime('2015-05-27 18:45:31');
Thes use $unix_timestamp in your SQL query.
Also you can use TIMESTAMP '2015-05-27 18:45:31' notation right in SQL statement.
If you have another format of date, you can use DateTime::createFromFormat
In your case:
$dateString = '2015-05-27 18:45:31';
$format = 'Y-m-d H:i:s';
$dateConvert = DateTime::createFromFormat($format, $dateString);
echo "Date: $format; " . $dateConvert->format('Y-m-d H:i:s') . "\n";
The output would be something like:
Date: Y-m-d H:i:s; 2015-05-27 18:45:31