Wednesday, January 20, 2016

PHP DATE AND TIME FORMAT: Format Date From Database

Date functions lets you get and format the date and time for use in queries, calendar functions and printing of date and time.

The date() function returns the current server timestamp and you can format it according to a set of parameters. The syntax is date(format,timestamp); If timestamp is not given, current date and time is assumed.

Here are some date() function formats for your reference.

Usually, the format that we used to save date in our table is Y-m-d in which the result is something like this: 2016-01-21. So to make your date more readable to users, you need to format it.

$date_posted="1970-01-01";//Let's just assume that the value from the table is like that.
echo date("M d, Y",strtotime($date_posted));

Output Date and Time Format

Hope this helps! Good day guys! ^_^

PHP DATE FORMAT: Format Date From Database

No comments:

Post a Comment