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.
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') . "\n";
echo 'Next Week: ' . date('Y-m-d', $nextWeek) . "\n";
// or using strtotime():
echo 'Next Week: ' . date('Y-m-d', strtotime('+1 week')) . "\n";
?>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.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.