PHP implements time addition and subtraction function strtotime usage

墨辰丷
Release: 2023-03-27 17:06:01
Original
2915 people have browsed it

This article mainly introduces the usage of the time addition and subtraction function strtotime in PHP. It analyzes the operation skills of strtotime combined with the date function to perform date addition and subtraction operations in the form of examples. Friends in need can refer to it

TimeAddition and Subtraction

<?php
//获取本地 提取年份+1
$date=date("Y-m-d",mktime(0,0,0,date("m") ,date("d"),date("Y")+1));
?>
Copy after login

What should I do if I want to get the time in the database? I found a good function strtotime in the PHP documentation, which can add and subtract time:

int strtotime (string time [, int now])

return Functions of type int

can be used for time conversion and addition and subtraction.

<?php
//date()格式化时间返回String类型。
//加一年
$date_year = date(&#39;Y-m-d&#39;,strtotime("$date + 1 year"));
echo $date_year;
//加一天
$date_tomorrow = date(&#39;Y-m-d&#39;,strtotime("2009-05-26 + 1 day"));
echo $date_tomorrow;
//加一周
$date_week = date(&#39;Y-m-d&#39;,strtotime("$date + 1 week"));
echo $date_week;
?>
Copy after login

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


Related recommendations:

PHP Detailed explanation of how to crawl and analyze web pages_php skills

PHPExplanation of common error prompts (practical! Worth collecting)_php skills

PHPAnalysis of solutions to the problem of inconsistent return values ​​when calling stored procedures_php skills

The above is the detailed content of PHP implements time addition and subtraction function strtotime usage. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!