PHP
  Home arrow PHP arrow Page 2 - Date/Time Processing with PHP
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
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

Date/Time Processing with PHP
By: The Disenchanted Developer, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2002-03-19

    Table of Contents:
  • Date/Time Processing with PHP
  • Getting A Date
  • A Stamp In Time...
  • Race Against Time
  • When Looks Do Matter
  • Checking Up
  • Turning The Tables

  • 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


    Date/Time Processing with PHP - Getting A Date


    (Page 2 of 7 )

    First up, before we get into anything too complicated, let's take a quick tour of the important date and time manipulation functions that come with PHP 4.1.
    The simplest and most basic thing you'll want to do with PHP's date API is, obviously, get the current date and time. This is best accomplished via the getdate() function, which returns an associative array containing date and time information.

    Here's an example:
    <?
    // get current date information as associative array
    $current = getdate();
    // print it
    print_r($current);
    ?>
    Here's what the output would look like:
    Array
    (
    [seconds] => 7
    [minutes] => 19
    [hours] => 9
    [mday] => 20
    [wday] => 3
    [mon] => 2
    [year] => 2002
    [yday] => 50
    [weekday] => Wednesday
    [month] => February
    [0] => 1014176947
    )
    This information can easily be manipulated and massaged into whatever format you like. For example,

    <? // get current date $current = getdate(); // turn it into strings $current_time = $current["hours"] . ":" . $current["minutes"] . ":" . $current["seconds"]; $current_date = $current["mday"] . "." . $current["mon"] . "." . $current["year"]; // print it // this would generate output of the form "It is now 9:14:34 on 23.5.2001" echo "It is now $current_time on $current_date"; ?>
    You can also give getdate() a timestamp, and have it convert that timestamp into an array for you. Consider the following example, which sends getdate() a UNIX timestamp for the date December 25 2001, and gets the information back as a much easier-to-read array:

    <? print_r(getdate(1009218600)); ?>
    The output is:

    Array ( [seconds] => 0 [minutes] => 0 [hours] => 0 [mday] => 25 [wday] => 2 [mon] => 12 [year] => 2001 [yday] => 358 [weekday] => Tuesday [month] => December [0] => 1009218600 )
    How did I create the timestamp? Flip the page to find out.

    More PHP Articles
    More By The Disenchanted Developer, (c) Melonfire


     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT