Format a PHP date for a given format

You will need some formatting for php date strings when you echo them or populating to db and other functions as well. You can first convert that accurate string to DateTime field in php and then format can be applied. Check below example.

calendar

$startDate = new DateTime( $row['startdate']);  
echo $startDate ->format('Y-m-d');
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s