Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform date to valid format for PostgreSQL with PHP

Tags:

date

php

I have a string in this format:

Thu, 26 Feb 2015 11:39:59

And I wonder if its possible to transform it to a valid timestamp format in order to insert it in my PostgreSQL database.

So ideally in the end I would have something like:

2015-03-26 11:39:59

Is there a function in PHP to do something like this?

like image 289
user1919 Avatar asked May 14 '15 09:05

user1919


1 Answers

Use DateTime() to format date string.

$date = 'Thu, 26 Feb 2015 11:39:59';

$date = new DateTime($date);

echo $date->format('Y-m-d H:i:s');
like image 168
Sougata Bose Avatar answered Oct 18 '22 12:10

Sougata Bose