Maison  >  Article  >  php教程  >  php日期相加减

php日期相加减

WBOY
WBOYoriginal
2016-06-08 17:30:161002parcourir
<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就也不难了.

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:php 无限级分类代码Article suivant:ajax验证用户名