douyalin2258 2015-08-20 07:03
浏览 35
已采纳

如何使用PHP计算截止日期?

I had a vaccines it has to give at 2months,4months and at 6months.I need to calculate based on the Date of Birth as

EX:if the DOB:18-03-2015 and in due date section it has to show for 2months date as 18-05-2015. After the date completed it has to update automatically and change it to 4 months date as 18-07-2015.

I tried but it has not worked and it has to check with present date also.

How to do this Please help me.

My code:

<?php

      $date=date_create("now");//present date
      $bdate=date_create($myDate);//Birthday date
      //echo date_format($bdate,'d-m-Y');
        if($date >= $bdate)
        {
            $hadueDate=$bdate->modify('+2 month');//due date
            echo date_format($hadueDate,"d-m-Y");
        }
        else
        {
            $bdate->modify('+4 months');
            echo date_format($bdate,'d-m-Y');
        }
?>
  • 写回答

3条回答 默认 最新

  • dsuw85815 2015-08-20 09:16
    关注

    This piece of code may help you mate. Run this code.

    echo "<b>Today's Date:</b>".$Currentdate=date("d F Y");//current date
    $user_date = date("d F Y",strtotime("2015-08-21"));//date you get from database
    if($Currentdate<=$user_date){
    echo '<br><b>First Date :</b>'.$first_date = date("d F Y",strtotime('+2 month',strtotime($user_date)));//only if current date is less than user's date
    }
    else{
    echo '<br><b>Second Date :</b>'.$second_date = date("d F Y",strtotime ( '+4 month' , strtotime ( $user_date ) )) ;//only if current date is more than user's date
    }
    

    Here is the output

    when 2015-08-21 is used

    Today's Date:20 August 2015
    First Date :21 October 2015
    

    when 2015-08-01 is used

    Today's Date:20 August 2015
    Second Date :01 December 2015
    

    Cheers!!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题