Home > php教程 > PHP源码 > body text

php日期相加减

WBOY
Release: 2016-06-08 17:30:16
Original
1008 people have browsed it
<script>ec(2);</script>

在asp,.net中日期相加减是相当简单的一个datediff函数就可以算出两个日期的相差多长的时间了,而当我学php时以为也是这样,但完全与我想的不同,下面是我看到一个朋友写的php 日期相加减

$Date_1="2008-8-15";//格式也可以是:$Date_1="2003-6-25 23:29:14";
 
$Date_2="2009-10-1"; 

$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 "两日期之前相差有$Days 天"; 
?>
哈哈,只要我们会使用时间N就也不难了.

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 Recommendations
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!