By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

PHP Time

The time function of PHP, and Example of usage.

Edited: 2016-01-09 07:47

The time function of PHP outputs the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

The output can be used as a timestamp in database entries, and is very useful for this purpose, as it allows for easy database querying.


echo time();

Should output something like: 14792462

From unix to readable timestamp

The timestamps produced by the PHP time function can be transformed into "readable" dates with the date function. I.e.:

$time = time();
echo "<p>" . date('Y-m-d', $time) . "</p>";

The Y represents the year in 4 digit, and the m is the numeric representation of a month with leading zeros, and finally the d represents the day in 2 digits with leading zeros.