您的位置:首页 > 编程语言 > PHP开发

php实现比较两个字符串日期大小的方法

2016-07-13 10:34 921 查看

<?php

function
dateBDate(
$date1
,
$date2
){

//日期1是否大于日期2

$month1
=
date
(
"m"
,
strtotime
(
$date1
));

$month2
=
date
(
"m"
,
strtotime
(
$date2
));

$day1
=
date
(
"d"
,
strtotime
(
$date1
));

$day2
=
date
(
"d"
,
strtotime
(
$date2
));

$year1
=
date
(
"Y"
,
strtotime
(
$date1
));

$year2
=
date
(
"Y"
,
strtotime
(
$date2
));

$from
=
mktime
(0,0,0,
$month1
,
$day1
,
$year1
);

$to
=
mktime
(0,0,0,
$month2
,
$day2
,
$year2
);

if
(
$from
>
$to
){

return
true;

}
else
{

return
false;

}

}

?>

$date1
=
"2009-10-13"
;

$date
=
mktime
(0,0,0,
date
(
"m"
,
strtotime
(
$date1
)),
date
(
"d"
,
strtotime
(
$date1
)),
date
(
"Y"
,
strtotime
(
$date1
)));

转:http://www.oschina.net/code/snippet_1182885_56205
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: