greenbandit
greenbandit

Reputation: 2275

date format function

Maybe is a dumb question, but I can't find the proper function:

I have a string date like 04/05/2012

How I can pass to this format: 2012-04-05 20:18:11 to insert in mySQL?

Upvotes: 0

Views: 173

Answers (3)

hjpotter92
hjpotter92

Reputation: 80639

Time can not be 'made' on its own. If you're however inserting the current date-time setting, then the following code will be used:

$dt = date( "Y-m-d H:i:s", time() );

You may use dleiftah's statement, but the time in that case will always be 00:00:00

Upvotes: 1

dm03514
dm03514

Reputation: 55952

$dateTime = new DateTime($your_time_string);
echo $dateTime->format("Y-m-d H:i:s");

Upvotes: 1

keithhatfield
keithhatfield

Reputation: 3273

Combination of date and strtotime ...

$my_date = date('Y-m-d H:i:s',strtotime('04/05/2012'));

Upvotes: 3

Related Questions