close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Web development tutorial

Formatting your dates (and times)

Tutorial created by Christopher West, Freelancer Looking for Work

Categories: PHP

rating

When storing date or datetime in the MySQL database it stores it in american format, for example:

2013-04-12 02:12:26

So when it comes for the need to output the above datetime to your website page, you would probably want to display it in a more user-friendly manner.

To view the PHP datetime attrributes visited the official PHP manual: http://php.net/manual/en/function.date.php

arrow downFormatting DateTime from your Database Table

Here are some suggestions using PHP code and the corresponding display output ...

Step 1: Display as: Friday 12th April 2013

<?php echo date('l jS F Y',strtotime($row_YourRecordSet['YourTableName'])); ?>

Step 2: Display as: Friday 12th Apr 2013

<?php echo date('l jS M Y',strtotime($row_YourRecordSet['YourTableName'])); ?>

arrow downFormatting Current DateTime from the Server

This section is based on formatting the current datetime stamp from the LINUX server your website is hosted on:

Step 1: Display as: Friday 12th April 2013 3:59am

<?php echo date('l jS F Y G:sa'); ?>

Step 2: Display as: Friday 12th Apr 2013 3:58am

<?php echo date('l jS M Y G:sa'); ?>

Step 3: Display as: Friday 12th April 2013

<?php echo date('l jS F Y'); ?>

Step 4: Display as: Friday 12th Apr 2013

<?php echo date('l jS M Y'); ?>

arrow downReviews and comments

Comments will be sent to the author of this tutorial and may not be answered immediately. For general help from WebAssist, please visit technical support.

Sign in to add comments
rating

serhat_alpaslan: 3 Years, 3 Months, 2 Weeks, 5 Days, 1 Hour, 18 Minutes ago

thanks

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.