开发者

date function help

I have this invoice with todays date:

I want to display the expiration date (30 days late开发者_运维知识库r), is there a function that allows this?

or is it something simple like adding a +30 somewhere?

Help :D


$date = date();

$future = date_add($date, date_interval_create_from_string('30 days'));

is the procedural way to do it. There's also an OOP version documented here as well.


You can use a combination of date() and strtotime().

echo date('Y-m-d', strtotime('+30 days'));

For more information on specifying date formats, see the manual page for date().


I hope it will help you.

$thirtydaysadd = mktime(0, 0, 0, date("m"), date("d")+1, date("y"));
echo "That day will be ".date("m/d/y", $thirtydaysadd); 

mktime() is used to create new time stamp.


strtotime is probably your best bet.

echo strtotime("+30 days"), "\n";

http://php.net/manual/en/function.strtotime.php


When you face such problems, PHP online documentation is very useful.

Just for to http://php.net/keyword (for example, http://php.net/date) and documentation page for that keyword will be displayed. You could see Date/Time functions in the left sidebar which has the link to function date_add

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜