Logo         Community
The Company
Your Account
Contact Us
Date/Time Processing With PHP
Simplify date and time processing in your PHP scripts

| Checking Up |

Options to getdate() include the localtime() and gettimeofday() functions, both of which return arrays containing time information. Take a look:

// get current time as array
$current = gettimeofday();

// print it

This would generate the following output:

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
    [sec] => 1014189678
    [usec] => 900172
    [minuteswest] => -19800
    [dsttime] => 0

Alternatively, you can use the localtime() function, which calls the system's localtime() function and returns the output as an array containing information similar to that returned by getdate(). Take a look:

// get current time as array
// the second parameter tells PHP to create an associative array
// omit it to create a regular integer-indexed array
$current = localtime(mktime(), TRUE);

// print it

Here's the output:

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
    [tm_sec] => 51
    [tm_min] => 54
    [tm_hour] => 12
    [tm_mday] => 20
    [tm_mon] => 1
    [tm_year] => 102
    [tm_wday] => 3
    [tm_yday] => 50
    [tm_isdst] => 0

It's unlikely that you'll ever use these, since most of what they provide is already available via the functions discussed previously. However, they're included here in case you ever have a need for this specialized information.

Finally, the checkdate() function tells you whether a given date is valid or not. Consider the following examples:

// 31-Feb-2002 - false
echo checkdate(02, 31, 2002);

// 25-Dec-1956 - true
echo checkdate(12, 25, 1956);

// 31-Jun-2002 - false
echo checkdate(06, 31, 2002);

This function comes in particularly handy if you need to validate date information entered into an online form - simply run the datestamp via checkdate() to see whether or not it's valid.

How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!

previous page more like this  print this article  next page
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Creating Web Calendars With The PEAR Calendar Class
Caching Web Sites With PEAR Cache
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
In cut!...
American Chai
The Core
Find out how you can use this article on your own Web site!

Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback