Home  >  Article  >  Backend Development  >  PHP code sharing for date addition and subtraction calculations

PHP code sharing for date addition and subtraction calculations

小云云
小云云Original
2018-03-01 13:40:081558browse

PHP standard date format

date("Y-m-d H:i:s");

PHP Simple date addition and subtraction calculation


##1

2

3

4

5

6

7

8

9

10

11

12

13

14


#

date_default_timezone_set('PRC'); //Default time zone<p class="line number3 index2 alt2" style="background-image:none;border:0px;float:none;margin:0px;padding:0px 1em;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"><code class="php spaces" style="font-size:1em;font-family:Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace;background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;min-height:auto;"> echo "Today:",date( "Y-m-d",time()),"\n";

echo "Today:",date( "Y-m-d",strtotime("18 june 2008")), "\n";

echo "Yesterday:",date( "Y-m-d",strtotime("-1 day")), "\n";

echo "Tomorrow:",date( "Y-m-d",strtotime("+1 day")), "\n";

echo "One week later:",date("Y-m-d",strtotime("+1 week")),"\n";

echo "One week, two days, four hours and two seconds later:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "\n";

echo "Next Thursday:",date("Y-m-d",strtotime("next Thursday")),"\n";

echo "Last Monday:".date("Y-m-d",strtotime("last Monday"))."\n";

echo "One month ago:".date("Y-m-d",strtotime("last month"))."\n";

echo "One month later:".date("Y-m-d",strtotime("+1 month"))."\n";

echo "Ten years later:".date("Y-m-d",strtotime("+10 year"))."\n";

?></p> </td> </tr></tbody></table> <p style="margin-top:10px;margin-bottom:10px;color:rgb(51,51,51);"><strong><br>Run result: </strong></p> <table border="0" style="background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:1em;min-height:auto;"><tbody style="background:none;float:none;margin:0px;padding:0px;vertical-align:baseline;font-size:1em;min-height:auto;"><tr style="background:none;border-top:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;font-size:1em;min-height:auto;" class="firstRow"> <td class="gutter" style="vertical-align:baseline;background:none;border-width:0px;float:none;margin:0px;padding:0px;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:1em;min-height:auto;color:rgb(175,175,175);"> <p class="line number1 index0 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">1</p> <p class="line number2 index1 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">2</p> <p class="line number3 index2 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">3</p> <p class="line number4 index3 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">4</p> <p class="line number5 index4 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">5</p> <p class="line number6 index5 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">6</p> <p class="line number7 index6 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">7</p> <p class="line number8 index7 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">8</p> <p class="line number9 index8 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">9</p> <p class="line number10 index9 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">10</p> <p class="line number11 index10 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">11</p> </td> <td class="code" style='vertical-align: baseline; background: none; border-width: 0px; float: none; margin: 0px; padding: 0px; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; font-size: 1em; min-height: auto; word-break: break-all;'> <p class="container" style="background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;font-size:1em;min-height:auto;"><br></p> <p class="line number1 index0 alt2" style="background-image:none;border:0px;float:none;margin:0px;padding:0px 1em;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"><code class="bash plain" style="font-size:1em;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;min-height:auto;color:#000000;">Today: 2017-11-06

Today: 2008-06-18

##Yesterday: 2017-11- 05

##Tomorrow: 2017-11-07

One week later: 2017-11-13

One week, two days, four hours and two seconds later: 2017-11-15 22:22:42

Next Thursday: 2017-11-09

Last Monday:2017-10-30

One month ago:2017-10-06

One month later :2017-12-06

<p class="line number11 index10 alt2" style="background-image:none;border:0px;float:none;margin:0px;padding:0px 1em;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"><code class="bash plain" style="font-size:1em;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;min-height:auto;color:#000000;">Ten years later: 2027-11-06


PHP Advanced Date Addition and Subtraction Calculation

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15


#

//Default time zone

​​ date_default_timezone_set('PRC');

    echo "Today: ", date( 'Y-m-d H:i:s'), "\n";        // Output the current time

    echo "Tomorrow: ", date( 'Y-m-d H:i:s', strtotime('+1 day')), "\n";           //Output tomorrow’s time

                         <p class="line number8 index7 alt1" style="background-image:none;border:0px;float:none;margin:0px;padding:0px 1em;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"><code class="php spaces" style="font-size:1em;font-family:Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace;background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;min-height:auto;"> //strtotime can accept the second parameter, the type timestamp is the specified date

    echo date('Y-m-d H:i:s', strtotime ("+1 day", strtotime('2017-11-11'))), "\n";

// +1 day here can modify parameter 1 to whatever you want The number

// day can also be changed to year (year) month (month) hour (hour) minute (minute) second (second)

    echo date('Y-m-d H:i:s', strtotime("+1 day +1 hour +1 minute")), "\n";

?></p> </td> </tr></tbody></table> <p style="margin-top:10px;margin-bottom:10px;color:rgb(51,51,51);">Run results:</p> <p style="margin-top:10px;margin-bottom:10px;color:rgb(51,51,51);"><span style="color:rgb(0,0,255);">Today: 2017-11-06 18:58:04<br>Tomorrow: 2017-11-07 18:58:04<br>2017-11-12 00:00:00<br>2017-11-07 19:59:04</span></p> <p style="margin-top:10px;margin-bottom:10px;color:rgb(51,51,51);"> </p> <p style="margin-top:10px;margin-bottom:10px;color:rgb(51,51,51);"><span style="color:rgb(178,34,34);"><strong>PHP Advanced Calculation of Date and Time Difference</strong></span></p> <p class="syntaxhighlighter php" style="margin:1em 0px;font-size:1em;"><br></p> <table border="0" style="background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:1em;min-height:auto;"><tbody style="background:none;float:none;margin:0px;padding:0px;vertical-align:baseline;font-size:1em;min-height:auto;"><tr style="background:none;border-top:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;font-size:1em;min-height:auto;" class="firstRow"> <td class="gutter" style="vertical-align:baseline;background:none;border-width:0px;float:none;margin:0px;padding:0px;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:1em;min-height:auto;color:rgb(175,175,175);">##1<p class="line number1 index0 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>2<p class="line number2 index1 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>3<p class="line number3 index2 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>4 <p class="line number4 index3 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>5<p class="line number5 index4 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>6<p class="line number6 index5 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>7<p class="line number7 index6 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>8<p class="line number8 index7 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>9<p class="line number9 index8 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>10<p class="line number10 index9 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>11<p class="line number11 index10 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>12<p class="line number12 index11 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p> <p class="line number13 index12 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">13</p> <p class="line number14 index13 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">14</p> <p class="line number15 index14 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">15</p> <p class="line number16 index15 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">16</p> <p class="line number17 index16 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">17</p> <p class="line number18 index17 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">18</p> <p class="line number19 index18 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">19</p> <p class="line number20 index19 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">20</p> <p class="line number21 index20 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">21</p> <p class="line number22 index21 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">22</p> <p class="line number23 index22 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">23</p> <p class="line number24 index23 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">24</p> <p class="line number25 index24 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">25</p> <p class="line number26 index25 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">26</p> <p class="line number27 index26 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">27</p> <p class="line number28 index27 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">28</p> <p class="line number29 index28 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">29</p> <p class="line number30 index29 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">30</p> <p class="line number31 index30 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">31</p> <p class="line number32 index31 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">32</p> <p class="line number33 index32 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">33</p> <p class="line number34 index33 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">34</p> <p class="line number35 index34 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">35</p> </td> <td class="code" style="vertical-align:baseline;background:none;border-width:0px;float:none;margin:0px;padding:0px;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:1em;min-height:auto;"> <p class="container" style="background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;font-size:1em;min-height:auto;"><br></p> <p class="line number1 index0 alt2" style="background-image:none;border:0px;float:none;margin:0px;padding:0px 1em;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">##<?php<code class="php plain" style="font-size:1em;font-family:Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace;background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;min-height:auto;color:#000000;">

##​

//Default time zone<p class="line number3 index2 alt2" style="background-image:none;border:0px;float:none;margin:0px;padding:0px 1em;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"><code class="php spaces" style="font-size:1em;font-family:Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace;background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;min-height:auto;"> date_default_timezone_set('PRC');

echo date("Y-m-d H:i:s"), "\ n";

// Date and day addition function

    echo date('Y-m-d', strtotime('+1 day', strtotime('2016-09-12'))), "\n\n";

 

    echo strtotime('2016-09-12'), "\n";

    echo date("Y-m-d", '1473609600'), "\n";

echo date("Y-m-d", ' 1573609600'), "\n";

// Date and day addition function

    $d = "2016-09-12 10:12:20";

echo date("Y-m-d", strtotime ("$d +1 day")), "\n\n";

//Convert date to time

                                                                                                                       #$year=((int)substr("$d"

,0, 4)); //Obtained year

       $month=((int)substr("$d",5,2)); //Get the month

        $day=( (int)substr("$d",8,2)); //Get the number Number

        return mktime(0,0,0,$month,$day,$year);

    }

    echo date2time("2016-09-12"), "\n\n";

 

    $date_1="2066-09-12";

    $date_2="2016-09-12";

    $Date_List_a1=explode("-",$date_1);

    $Date_List_a2=explode("-",$date_2);

    $d1=mktime(0,0,0,$Date_List_a1[1],$Date_List_a1[2],$Date_List_a1[0]);

    $d2=mktime(0,0,0,$Date_List_a2[1],$Date_List_a2[2],$Date_List_a2[0]);

    $Days=round(($d1 -$d2)/3600/24);

##​ echo "$date_2 -> $date_1 difference: $Days days", "\n";

?>

Running results:


1

2

3

4

5

6

7

8

9

10

11


2017-11-06 19:13:02

##2016-09-13

1473609600

2016-09-12

2019-11-13

2016- 09-13

1473609600

2066-09-12 -> 2016- 09-12 Difference: 18262 days

Related recommendations:

Oracle time and date addition and subtraction calculation

PHP date and time

PHP date and time functions

The above is the detailed content of PHP code sharing for date addition and subtraction calculations. 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