PHP
  Home arrow PHP arrow Page 3 - Working with Dates and Times in PHP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Working with Dates and Times in PHP
By: Hermawan Haryanto
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2003-03-07

    Table of Contents:
  • Working with Dates and Times in PHP
  • First Step
  • Display it to human readable date and time format
  • Make my own date time
  • Another method
  • My own Language

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working with Dates and Times in PHP - Display it to human readable date and time format


    (Page 3 of 6 )

    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.

    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 PHP Articles
    More By Hermawan Haryanto


       · Thank you for this great article! I would like to share the list of human readable...
       · Excellent article - thanks much!
     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek