Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   PHP Date function help required (https://www.warriorforum.com/programming/810416-php-date-function-help-required.html)

wizwebtechno 6th July 2013 02:25 AM

PHP Date function help required
 
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

bugtrack 6th July 2013 02:43 AM

Re: PHP Date function help 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

Paul Moss 6th July 2013 01:55 PM

Re: PHP Date function help required
 
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');

weaveronline 7th July 2013 02:28 PM

Re: PHP Date function help required
 
Hope this helps

<?php
echo date("jS F", strtotime('+15 days'));
?>

octalsoftware 12th July 2013 01:14 AM

Re: PHP Date function help required
 
<?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


All times are GMT -6. The time now is 11:58 AM.