需要在日期中添加几周,几天和几个月才能订阅软件包 [英] Need to add weeks, days and months in a date for a package subscription
问题描述
我目前正在为我当前的项目使用软件包管理器,我需要添加软件包订阅日期和软件包到期日期.
I am currently working on a package manager for my current project and I need to add package subscription date and package expiry date.
我正在使用php函数 date("Y-m-d H:i:s")
即
I am using php function date("Y-m-d H:i:s")
i.e
$package_subscription_start_date = date("Y-m-d H:i:s");
现在这是我的要求:我需要1天,2天,5天,1周,4周,12周,1个月,6个月,9个月,1年,2年,5年和10年这样的套餐.
now here is my requirement: I need to have packages such as for 1 day, 2 days, 5 days, 1 week, 4 weeks, 12 weeks, 1 month, 6 months, 9 months, 1 year, 2 years, 5years and 10 years.
我怎么可能添加这些值并计算要插入到mysql中的程序包的有效期,例如
How is it possible for me to add these values and calculate the package expiry date for inserting into mysql, something like
$package_expiry_date = date("Y-m-d H:i:s") + 1 day;
$package_expiry_date = date("Y-m-d H:i:s") + 5 days;
$package_expiry_date = date("Y-m-d H:i:s") + 1 week;
$package_expiry_date = date("Y-m-d H:i:s") + 4 weeks;
$package_expiry_date = date("Y-m-d H:i:s") + 2 months;
$package_expiry_date = date("Y-m-d H:i:s") + 2 years;
最后,我需要处理其他日期问题,例如有效日期和leap年等.另外,我需要在php级别上完成此操作,而不是使用mysql/sql查询.
Lastly I need to take care of other date issues like valid date and leap year etc. Also I need this to be done at php level, not using mysql / sql query.
在此方面的任何帮助,我将不胜感激.
I will appreciate any help in this direction.
推荐答案
您是否尝试过php中的strtotime()命令?
echo $expires = strtotime(date("Y-m-d H:i:s")." + 1 day");
echo date("Y-m-d H:i:s", $expires);
为您提供
135082420020
12-10-21 08:56:40
这篇关于需要在日期中添加几周,几天和几个月才能订阅软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!