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)); ?>
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('Y-m-d',strtotime("$date + 1 year")); echo $date_year; //加一天 $date_tomorrow = date('Y-m-d',strtotime("2009-05-26 + 1 day")); echo $date_tomorrow; //加一周 $date_week = date('Y-m-d',strtotime("$date + 1 week")); echo $date_week; ?>
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
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!