PHP time() Function – Returning the Current Unix Timestamp

This article explains PHP's time() function, which returns the current Unix timestamp, and demonstrates how to calculate and display the current date and the date one week later using both arithmetic and strtotime methods.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP time() Function – Returning the Current Unix Timestamp

The time() function in PHP returns the number of seconds that have elapsed since the Unix epoch (January 1, 1970 00:00:00 UTC).

Example usage shows how to compute the timestamp for one week from now by adding the appropriate number of seconds (7 days × 24 hours × 60 minutes × 60 seconds) to the current timestamp, and then format both the current date and the future date with date():

<?php
$nextWeek = time() + (7 * 24 * 60 * 60);

echo 'Now: ' . date('Y-m-d') . "
";

echo 'Next Week: ' . date('Y-m-d', $nextWeek) . "
";
// or using strtotime():

echo 'Next Week: ' . date('Y-m-d', strtotime('+1 week')) . "
";
?>

The script first prints the current date, then prints the date exactly one week later using the calculated timestamp, and finally shows an alternative approach using strtotime('+1 week') to achieve the same result.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

time
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.