How to convert to a specific date format in PHP?

Date is something which could be represented or described in many different ways. For Instance the date today could be represented in the following ways-

20th March 2018

03/20/18

20/03/18

2018/03/20

And so on

So, it is Important to know how would one convert from one format to another.

The first thing to do is set a default date format.

date_default_timezone_set('EST');

 

Then if you want the output of the date to be as month/day/year

$date_formatted=date("m/d/Y",strtotime($date));

 

This statement can be modified to the format that you require.

You need to pay attention to the characters that are used to describe the dates, they are case sensitive.

This would give you a detailed explanation on the characters and their description.

 

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s