English 中文(简体)
补充日
原标题:Add days to a date in PHP

Is there any php function available where I can add days to a date to make up another date? For example, I have a date in the following format: 27-December-2011

If I add 7 to the above, it should give: 03-January-2012.

很多人

最佳回答

引言

$add_days = 7;
$date = date( Y-m-d ,strtotime($date) + (24*3600*$add_days));
问题回答

看看这种简单的幻灯

$date = date("Y-m-d");// current date

$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +2 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 month");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +30 days");

您可使用add 日期方法。 任何途径,这种解决办法都用于“S.C.”版本,即5.3。

date( Y-m-d , strtotime( +6 days , strtotime($original_date)));

实际上,这比一切都容易。

$some_var = date("Y-m-d",strtotime("+7 day"))

You can use a variable instead of the string, of course. It will be great if the people answering the questions, won t complicate things. Less code, means less time to waste on the server ;).

$date = new DateTime( 27-December-2011 );
$date->add(new DateInterval( P7D ));
echo $date->format( d-F-Y ) . "
";

改变描述的形式是你想要的。 (见date()。

$registered = $udata->user_registered;
$registered = date( "d m Y", strtotime( $registered ));
$challanexpiry = explode(   , $registered);
$day   = $challanexpiry[0];
$month = $challanexpiry[1];
$year  = $challanexpiry[2];
$day = $day+10;
$bankchallanexpiry = $day . " " . $month . " " . $year;




相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签