PHP Date function help required

by 4 replies
5
I am getting current date in php using date function but what I want is date before 15 days. I mean if today is 15th jan then i want it 1st Jan as a date.

Thanks
#programming #date #function #php #required
  • You can use strtotime function for that here is an example for what you are looking for

    PHP Code:
    date('Y-m-d'strtotime('-7 days')) 
    Hope it wills olve your problem
    • [1] reply
    • Or you can use if you are using greater than php 5.3


      $date = new DateTime(date("Y-m-d"));
      $date->modify('-15 day');
      echo $date->format('Y-m-d');
  • Hope this helps

    <?php
    echo date("jS F", strtotime('+15 days'));
    ?>
  • <?php
    echo date("Y/m/d") . "<br>";
    echo date("Y.m.d") . "<br>";
    echo date("Y-m-d");
    ?>

    output::
    2013/07/12
    2013.07.12
    2013-07-12

Next Topics on Trending Feed