您正在使用 IPV4 [18.97.14.90] 访问本站,您本次已经查看了 1 页
用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器
[公益]保护绿色环境,构建和谐社会      

【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中      
广州婚姻调查公司       [公益] 地球是我家,绿化靠大家       【腾讯云】618年中盛惠,2核2G5M云服务器低至 68元/年      
2025年 七夕节 067
2025年 教师节 079
2026年 元 旦 192
2026年 春 节 239
综合数码金融娱乐服务报刊政府机构 推荐 排名 今日 申请 友情  
您现在的位置:首页 >> PHP >> 内容
本类新增
本类热门
php实现比较两个字符串日期大小的方法
内容摘要: ?phpfunctiondateBDate($date1,$date2){//日期1是否大于日期2$month1=date('m',strtotime($date1));$month2=date('m',strtotime($date2));$day1=date('d',strtotime($date1));$day2=date('d',strtotime(......
<?php

functiondateBDate($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){

returntrue;

}else{

returnfalse;

}

}

?>

$date1="2009-10-13";

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

最终取得一个日期的Unix时间戳$date=1255392000。

很多时候做搜索的时候,搜索的时间不能大于当前日期,比较函数的写法大致和上面一个函数相同,具体如下:

functiondateBCurrent($date){

//日期是否大于当前日期

$currentDate=date("Y-m-d");

//获取当前日期

$cYear=date("Y",strtotime($currentDate));

$cMonth=date("m",strtotime($currentDate));

$cDay=date("d",strtotime($currentDate));

$year=date("Y",strtotime($date));

$month=date("m",strtotime($date));

$day=date("d",strtotime($date));

$currentUnix=mktime(0,0,0,$cMonth,$cDay,$cYear);

//当前日期的Unix时间戳

$dateUnix=mktime(0,0,0,$month,$day,$year);

//待比较日期的Unix时间戳

if($dateUnix<=$currentUnix){

returntrue;

}else{

returnfalse;

}

}

版权声明:本内容来源于网络,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
上一篇:php逐行读取txt文件写入数组的方法

 

下一篇:php获取mysql字段名称和其它信息的例子

发布日期:2025/3/9
手机扫二维码直达本页
发布时间:21:16:26
点  击:24
录  入:壹家怡园
相关文章
Baidu
YiJiaCMS 7.5.8 build250610(MSSQL) 闽ICP备05000814号-1
本空间由腾讯云(轻量应用服务器)提供,创宇云安全提供加速防护
运行时间载入中.....
知道创宇云安全