get current date and date after two months in php

后端 未结 3 1305
悲&欢浪女
悲&欢浪女 2020-12-19 12:10

this is a very lame question but i m not able to find this one. How to get today\'s date and date after two months..

format is month-date-year (numerical.)

3条回答
  •  感动是毒
    2020-12-19 12:30

    There are a couple of ways you could go about it - the first one would be to do something like this:

    echo $currentdate = date("Y-m-d H:i:s",time());    
    echo $after60days = date('Y-m-d H:i:s', time() + 60 * 60 * 24 * 60);
    

    Basically, you take the current timestamp, expressed in seconds, and add 60 * 60 * 24 * 60, which is the amount of seconds in two months.

    Another way to do it, which is my preferred way and how I would do it, is this:

    $after60days = strtotime("+60 days");
    

    The outcome will be exactly the same, $after60days will have a value equal to the timestamp of the day exactly two month from now, but it uses PHP's own strtotime() function.

    Of course, if you need to output a date in a format that easy to read for humans, you can do something like this:

    echo date('Y-m-d H:i:s',$after60days);
    

提交回复
热议问题