PHP date_sub() 函数
PHP date_sub() 函数
实例
从 2013 年 3 月 15 日减去 40 天:
<?php
$date=date_create("2013-03-15");
date_sub($date,date_interval_create_from_date_string("40 days"));
echo date_format($date,"Y-m-d");
?>
$date=date_create("2013-03-15");
date_sub($date,date_interval_create_from_date_string("40 days"));
echo date_format($date,"Y-m-d");
?>
运行实例 »
定义和用法
date_sub() 函数从指定日期减去日、月、年、时、分和秒。
语法
date_sub(object,interval);
参数 | 描述 |
---|---|
object | 必需。规定一个由 date_create() 返回的 DateTime 对象。 |
interval | 必需。规定一个 DateInterval 对象。 |
技术细节
返回值: | 如果成功则返回 DateTime 对象,如果失败则返回 FALSE。 |
---|---|
PHP 版本: | 5.3+ |

相关文章
- PHP 简介
- PHP 魔术常量
- PHP date() 函数
- PHP 包含文件 include 和 require 语句
- PHP array_combine() 函数
- PHP array_diff_assoc() 函数
- PHP array_merge_recursive() 函数
- PHP array_multisort() 函数
- PHP array_product() 函数
- PHP array_udiff_uassoc() 函数
- PHP array_uintersect_assoc() 函数
- PHP array_uintersect_uassoc() 函数
- PHP array_unshift() 函数
- PHP arsort() 函数
- PHP each() 函数
- PHP extract() 函数
- PHP reset() 函数
- PHP sizeof() 函数
- PHP uksort() 函数
- PHP 5 Math 函数