Miscellaneous

  Home arrow Miscellaneous arrow Page 2 - Working with dates and times in PHP
MISCELLANEOUS

Working with dates and times in PHP
By: Hermawan Haryanto
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-11-12

    Table of Contents:
  • Working with dates and times in PHP
  • Human Readable Formats
  • Making your own date and time
  • My own Language

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Working with dates and times in PHP - Human Readable Formats


    (Page 2 of 4 )

    Now, we want to display that timestamp in a human readable format. To do that we have to understand the date() function. This date function is used to convert from a UNIX timestamp to a human readable date. The date function is:

    string date ( string format [, int timestamp])

    You can see that the timestamp is rounded by ‘[‘ and ‘]’, that means it’s optional. If we put it then the function will use it and if we don’t put it then the function will use the default timestamp. The default timestamp which is used when we don't put any timestamp is the current time.

    Let’s start our work with the date function. We want to show the user what date and time is now.

    <?php
    print date("l, F jS Y – H:i:s");
    ?>

    As you can see on the example above, I use l, F jS Y - H:i:s as the variable passed to the function. Here is a list of formatting characters used:

    F - month, textual, long; e.g. "January" 
    H - hour, 24-hour format; i.e. "00" to "23" 
    i - minutes; i.e. "00" to "59" 
    j - day of the month without leading zeros; i.e. "1" to "31" 
    l (lowercase 'L') - day of the week, textual, long; e.g. "Friday" 
    s - seconds; i.e. "00" to "59" 
    S - English ordinal suffix for the day of the month, 2 characters; i.e. "st", "nd", "rd" or "th" 
    Y - year, 4 digits; e.g. "1999"

    For a complete list of formatting characters, see the manual page at http://www.php.net/manual/en/function.date.php

    More Miscellaneous Articles
    More By Hermawan Haryanto

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap