how to list next 30 days from current date in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
namikun
Forum Newbie
Posts: 6
Joined: Sun Nov 06, 2011 9:14 am

how to list next 30 days from current date in php

Post by namikun »

Hello guys!i'm now in learning process. i tried to list next 30 days from current date but never success. How to do it? hope you willing to help me :)
Example: 1/1/2011, 2/1/2011, 3/1/2011,4/1/2011 .......until 30/1/2011.

<?php
echo date("d/m/y");
?>

<?php

$tomorrow = mktime(0, 0, 0, date("m"), date("d")+1, date("y"));

echo date ("<br><br> d/m/y <br><br>" , $tomorrow);

?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: how to list next 30 days from current date in php

Post by Celauran »

Code: Select all

$today = new DateTime();
for ($i = 1; $i <= 30; $i++)
{
    echo $today->add(new DateInterval('P1D'))->format('d/m/Y') . "<br />";
}
namikun
Forum Newbie
Posts: 6
Joined: Sun Nov 06, 2011 9:14 am

Re: how to list next 30 days from current date in php

Post by namikun »

thanks Celauran! now i can proceed to next level. =)
Post Reply