日期减去1年? [英] Date minus 1 year?

查看:115
本文介绍了日期减去1年?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的日期:

2009-01-01

如何在1年前返回相同的日期?

How do I return the same date but 1 year earlier?

推荐答案

您可以使用 strtotime

You can use strtotime:

$date = strtotime('2010-01-01 -1 year');

strtotime 函数返回一个unix时间戳,要获取格式化的字符串,您可以使用 date

The strtotime function returns a unix timestamp, to get a formatted string you can use date:

echo date('Y-m-d', $date); // echoes '2009-01-01'

这篇关于日期减去1年?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆