Posts Tagged ‘idate’

Easily grabbing the hour from PHP

April 14th, 2009 Comments off

Ever need to grab a portion of the current timestamp from PHP? Know how to grab the hour of the current time the server in MySQL using the HOUR() function, but not quite sure how to grab the hour through PHP? Try this handy little function in PHP:


According to the PHP manual page on idate (, the idate() function will:

“Returns a number formatted according to the given format string”

To make things easy, the idate function accepts only one format parameter and returns a single integer. To quickly and easily retrieve the hour of the current timestamp, just pass in the H parameter to the function.

For example:

$iHour = idate(‘H’);

To get the full list of parameters you can pass to the idate function, to see how the idate() differs from date(), or to find out more specifics, visit the idate function reference page here:

Categories: PHP Tags: , ,