PHP
  Home arrow PHP arrow Page 4 - Date/Time Processing with PHP
Dev Shed Forums 
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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 - Race Against Time


    (Page 4 of 7 )

    If you don't like mktime(), you can also use the time() function, which returns the current timestamp (note that you cannot use this function to generate arbitrary timestamps, as is possible with mktime()).

    If you need greater accuracy in your timestamp, take a look at the microtime() function, which returns a timestamp in seconds, together with an additional microsecond component. These two values can be added together to obtain a more precise timestamp value. Like time(), this function too cannot be used with arbitrary dates and times - it only returns a timestamp for the current instant.

    The microtime() function is particularly useful when you need to time events accurately, or when you need an arbitrary, unique number to seed PHP's random number generator. Here's an example of the former:
    <?
    // function to calculate timestamp in microseconds
    function tscalc()
    {
    // split returned timestamp
    $arr = explode(" ", microtime());
    // add microseconds to seconds 
    // to generate more precise timestamp 
    return $arr[0] + $arr[1];
    }
    // start time
    $start = tscalc();
    // do something
    // over here, run a loop
    $count = 0;
    $x = 0;
    while ($count < 500)
    {
    $x = $x + $count;
    $count++; 
    }
    // end time
    $end = tscalc();
    echo "Started at $start";
    echo "Ended at $end";
    echo "Total processing time was " . ($end-$start);
    ?>
    And here's an example of the latter:
    <?
    // function to calculate timestamp in microseconds
    function tscalc()
    {
    // split returned timestamp
    $arr = explode(" ", microtime());
    // add microseconds to seconds 
    // to generate more precise timestamp 
    return $arr[0] + $arr[1];
    }
    // seed random number generator
    srand(tscalc());
    // get a random number
    echo rand();
    ?>

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


     

       

    PHP ARTICLES

    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application





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