使用PHP减去日期后的几天,几个月或几年 [英] Subtracting days, months or years from date using php
本文介绍了使用PHP减去日期后的几天,几个月或几年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有('Y-m-d')
格式的日期字段startBefore
的数据库表.还有3个其他的int字段,分别表示年,月和日.我想做的是用'Y-m-d'
格式将这三个字段填写为新的startAfter
日期.
I have a db table with a date field startBefore
in ('Y-m-d')
format. There are also 3 other int fields representing years, months and days. What I would like to do is to fill these three fields the new startAfter
date in 'Y-m-d'
format.
例如,我将'2001-11-14'作为startBefore
日期,并且我想减去3年7个月零1天以获得startAfter
日期.
For example I have the '2001-11-14' as startBefore
date and I would like to subtract 3 yrs, 7 months, 1 day to get the startAfter
date.
有什么想法可以实现这一目标吗?
Any ideas how I can accomplish this?
谢谢!
推荐答案
使用strtotime('date -years -months -days')
<?php
$time = strtotime('2001-11-14 -3 years -7 months -5 days');
echo $date = date("Y-m-d", $time);
这篇关于使用PHP减去日期后的几天,几个月或几年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文