php 寻找相同日期,查找两个日期PHP之间特定日期的日期

尝试这个:

function getAllWednesday($from_date, $to_date){

// getting number of days between two date range.

$number_of_days = count_days(strtotime($from_date),strtotime($to_date));

for($i = 1; $i<=$number_of_days; $i++){

$day = Date('l',mktime(0,0,0,date('m'),date('d')+$i,date('y')));

if($day == 'wednesday'){

echo Date('d-m-Y',mktime(0,0,0,date('m'),date('d')+$i,date('y'))),'
';

}

}

}count_days()函数

function count_days( $a, $b )

{

// First we need to break these dates into their constituent parts:

$gd_a = getdate( $a );

$gd_b = getdate( $b );

// Now recreate these timestamps, based upon noon on each day

// The specific time doesn't matter but it must be the same each day

$a_new = mktime( 12, 0, 0, $gd_a['mon'], $gd_a['mday'], $gd_a['year'] );

$b_new = mktime( 12, 0, 0, $gd_b['mon'], $gd_b['mday'], $gd_b['year'] );

// Subtract these two numbers and divide by the number of seconds in a

// day. Round the result since crossing over a daylight savings time

// barrier will cause this time to be off by an hour or two.

return round( abs( $a_new - $b_new ) / 86400 );

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值