Jump to content

can not format the date correctly, please help


jasonc

Recommended Posts

What I am trying to do is grab the date part and format it as so..

 

dd-mm-yyyy

 

this is my code which shows the error...

 

Warning:  date_format() expects parameter 1 to be DateTime, string given in **** on line 25

 

how would i correctly get the date part and format it.

 

$post_time = "2010-04-26 18:12:00";
$datestring = date_format($post_time, 'd-m-Y');

Use strftime and strtotime

 

$post_time = "2010-04-26 18:12:00";
$time = strotime($post_time); //Convert to timestamp!
$datestring = strftime('%d-%m-%Y', $post_time);

 

Or as andrew said, use a date object.

 

thank you i used this reply to fix my coding.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.