Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php get future date time

Tags:

date

php

time

I don't know how to explain this correctly but just some sample for you guys so that you can really get what Im trying to say.

Today is April 09, 2010

7 days from now is April 16,2010

Im looking for a php code, which can give me the exact date giving the number of days interval prior to the current date.

I've been looking for a thread which can solve or even give a hint on how to solve this one but I found none.

like image 869
Sanjay Khatri Avatar asked Apr 09 '10 06:04

Sanjay Khatri


People also ask

How can I calculate date after 10 days in PHP?

echo date("Y-m-d", strtotime("+10 days", strtotime($start_date))); You try like above. Replace from "+10 days" to your desired value to get the number of days added as you wish.

How can I get next Monday date in PHP?

echo(strtotime("next Monday") . "<br>"); echo(strtotime("last Sunday"));

How can I get plus date in PHP?

The date_add() function adds some days, months, years, hours, minutes, and seconds to a date.


2 Answers

If you are using PHP >= 5.2, I strongly suggest you use the new DateTime object, which makes working with dates a lot easier:

<?php
$date = new DateTime("2006-12-12");
$date->modify("+7 day");
echo $date->format("Y-m-d");
?>
like image 157
ChrisR Avatar answered Sep 25 '22 07:09

ChrisR


Take a look here - http://php.net/manual/en/function.strtotime.php

<?php
// This is what you need for future date from now.
echo date('Y-m-d H:i:s', strtotime("+7 day"));

// This is what you need for future date from specific date.
echo date('Y-m-d H:i:s', strtotime('01/01/2010 +7 day'));
?>
like image 21
Ivo Sabev Avatar answered Sep 24 '22 07:09

Ivo Sabev