How can I get future date by php date() function, for example today is 11/13/2007, I want to get the date after 60 days.

Any advice will be appreciated.

Dani AI

Generated

pointed out the usual quick route and showed the basic snippet most people use. Those work fine for simple scripts, but for reliable, timezone-aware behavior prefer PHP's DateTime API. is also right that the database can do this when it makes sense to keep date logic in SQL.

Here is a clear, robust approach in PHP using DateTime and DateInterval:

$dt = new DateTime('now', new DateTimeZone('UTC'));
$dt->add(new DateInterval('P60D'));
echo $dt->format('Y-m-d');

If you prefer immutability (so the original object is not changed), use DateTimeImmutable:

$today = new DateTimeImmutable('2023-11-13', new DateTimeZone('UTC'));
$future = $today->add(new DateInterval('P60D'));
echo $future->format('m/d/Y');

If you want the database to calculate it instead, use a DATE_ADD call in MySQL:

SELECT DATE_ADD(CURDATE(), INTERVAL 60 DAY) AS future_date;

Notes and caveats: adding "60 days" with DateInterval (P60D) gives 60 calendar days and respects DST and timezone rules; adding a fixed number of seconds (60 * 86400) can be wrong across DST transitions. Use DateTime/DateInterval when you need precise calendar math, and DateTimeImmutable if you want functional-style code. When working across systems, set or check the timezone explicitly (see date_default_timezone_get() / date_default_timezone_set()), and choose the output format you need with format(). For API documentation, consult the PHP DateTime and DateInterval manuals and MySQL DATE_ADD docs for exact behavior and extra options.

Recommended Answers

All 3 Replies

You need to use strtotime().

<?php

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

echo 'After 60 days : '. date('Y-m-d', strtotime('+60 days')) ."\n";

?>
Member Avatar for Member #46692

You can also use mysql functions as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.