生日计算方法

php:
1.首先数据库里面查询出一个数组来
2.$users =    D('baoming_user')->where($maps)->select();
        foreach($users as $key=>$val){
            $date = explode("-",date("Y-m-d",$val['birthday']));//先把年月日拆分开
            $dateb = date("Y")."-".$date[1]."-".$date[2];//再把把年月日按当年合并起来
            $num = (strtotime($dateb)-strtotime(date("Y-m-d")))/86400;//然后相减除以86400得到天数
            if($num<7){//重新定义一个新的 数组。
                $user[$key]['id']             =$val['id'];
                $user[$key]['name']         =$val['baoming_name'];
                $user[$key]['birthday']     =date('Y-m-d',$val['birthday']);
                $user[$key]['count_down']     =$num;    //    倒计时天数
                $user[$key]['mobile']         =$val['mobile'];  
            }
        }
html:
<h6>生日提醒</h6>
        <div class="content">
                <table>
                    <tr>
                        <th>学员姓名</th>
                        <th>学员生日</th>
                        <th>生日倒计时</th>
                        <th>手机号</th>
                    </tr>
                    <volist name="user" id="us" offset="1" length='4'>
                    <tr>
                        <td>{$us.name}</td>
                        <td>{$us.birthday}</td>
                        <td>还有<span style="color:red; font-size:18px"> &nbsp;{$us.count_down} &nbsp;</span>天生日</td>
                        <td>{$us.mobile}</td>
                    </tr>
                    </volist>
                </table>
         <div class="bk20 hr"></div>     
       
        </div>
效果:

posted @ 2015-12-01 15:28  Sun丶老板  阅读(945)  评论(0编辑  收藏  举报