How to increase date in php

藏色散人
Release: 2023-03-11 16:14:01
Original
2882 people have browsed it

In PHP, you can use the "date('Y-m-d H:i:s',strtotime(" 1 day 1 hour 1 minute");" syntax to add a specific time to the date.

How to increase date in php

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

How to increase the date in php?

PHP adds one day to the current date and one day to the specified date

1. Add one day to the current time? One hour?

"; echo "明天:",date('Y-m-d H:i:s',strtotime('+1 day')); ?>
Copy after login

The previous line outputs the current time, and the next line outputs tomorrow's time

Similarly add one year, one hour, one minute, one month...

echo "明天:",date('Y-m-d H:i:s',strtotime('+1 day')); echo "明天:",date('Y-m-d H:i:s',strtotime('+1 hour')); echo "明天:",date('Y-m-d H:i:s',strtotime('+1 minute')); echo "明天:",date('Y-m-d H:i:s',strtotime('+1 mouth'));
Copy after login

Here 1 day can modify parameter 1 to any number you want. Day can also be changed to year (year), month (month) ), hour (hour) minute (minute), second (second) such as:

date('Y-m-d H:i:s',strtotime("+1 day +1 hour +1 minute");
Copy after login

can be freely combined to achieve the purpose of outputting any time

Note: This method is for 1970 It will be tried in the future, which is the applicable scope of the timestamp.

2. Add one day to the specified time? One hour?...

echo date("Y-m-d",strtotime("+1 month",strtotime("2012-02-04")));
Copy after login

The result is: 2011-03-04

echo date("Y-m-d",strtotime("+1 week",strtotime("2011-02-04")));
Copy after login

The result is: 2011-02-11

echo date("Y-m-d",strtotime("+1 day",strtotime("2011-02-04")));
Copy after login

The result is: 2011-02-05

Others are the same as above.

Note: This method It is aimed at trials after 1970, which is the scope of application of timestamps.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to increase date in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
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!