Home  >  Article  >  Backend Development  >  PHP method to implement addition and subtraction operations for dates, months, days, weeks, hours, minutes, seconds, etc.

PHP method to implement addition and subtraction operations for dates, months, days, weeks, hours, minutes, seconds, etc.

墨辰丷
墨辰丷Original
2018-05-23 16:49:361946browse

This article mainly introduces the PHP implementation of addition and subtraction operations for dates, months, days, weeks, hours, minutes, seconds, etc., and analyzes simple date and time operation techniques based on strtotime in the form of examples, which is very practical. Value, friends in need can refer to it

In fact, it is the built-in functionstrtotime


##

//PHP 日期 加减 周
date("Y-m-d",strtotime("2013-11-12 +1 week"))
//PHP 日期 加减 天数
date("Y-m-d",strtotime("2013-11-12 12:12:12 +1 day"))
//PHP 日期加减小时
date("Y-m-d h:i:s",strtotime("2013-11-12 12:12:12 +1 hour"))
//PHP 日期 加减 月数
date("Y-m-d",strtotime("2013-11-12 12:12:12 +1 month"))
//PHP 日期 加减 分
date("Y-m-d h:i:s",strtotime("2013-11-12 12:12:12 +1 minute"))
//PHP 日期 加减 秒
date("Y-m-d h:i:s",strtotime("2013-11-12 12:12:12 +1 second"))


The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

PHPSummary of mathematical operation functions (classics worth collecting)_php skills

PHPHow to format MYSQL to return float type_php tips

PHPCollection of mathematical operation functions (classics worth collecting)_php skills


The above is the detailed content of PHP method to implement addition and subtraction operations for dates, months, days, weeks, hours, minutes, seconds, etc.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn