Home arrow PHP arrow Page 3 - Date/Time Processing with PHP

A Stamp In Time... - PHP

Like most programming languages, PHP comes with a fairlyfull-featured API for date and time value manipulation. You've probablyused it in your applications, but never bothered to look too closely atit. Well, here's your chance to rectify that mistake - this articledelves into the date/time API in depth, uncovering some hidden nuggetsand demonstrating how it can be used to simplify date and timeprocessing in your PHP scripts.

TABLE OF CONTENTS:
  1. Date/Time Processing with PHP
  2. Getting A Date
  3. A Stamp In Time...
  4. Race Against Time
  5. When Looks Do Matter
  6. Checking Up
  7. Turning The Tables
By: The Disenchanted Developer, (c) Melonfire
Rating: starstarstarstarstar / 14
March 19, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Most of PHP's date functions work on the basis of timestamps. This timestamp is a unique numeric representation of a particular date, calculated as the number of seconds between January 1 1970 and the date and time specified, and makes it easier to perform arbitrary calculations on date and time values.

In PHP, UNIX timestamps are created via the mktime() function, which accepts a series of date and time parameters, and converts them into a timestamp. Here's an example:
<?
// get a timestamp for 14:35:20 April 1 2002
echo mktime(14, 35, 20, 4, 1, 2002);
?>
In this case, I've passed the mktime() function six parameters: the hour, minute, second, month, day and year for which I need a timestamp. The result is a long integer like this: 1017651920This integer can now be passed to getdate() - or any other date function that accepts timestamps - and converted into a human-readable representation.

You can obtain a timestamp for the current moment in time by calling mktime() with no arguments:
<?
// get a timestamp for now
echo mktime();
?>
Notice also that the "0" key of the array returned by getdate() contains a UNIX timestamp representation of the date returned.

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

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


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

Dev Shed Tutorial Topics: