Last updated on May 26th, 2016 at 01:11 pm

Find year month day before a date using PHP

This is just a simple script that display the year/month/day before a predefined date using php. This predefined date can be any date according to our convenience. Here i am defining my date as current date. Just see the script

$m= date("m");
$de= date("d");
$y= date("Y");
for ($i = 0; $i<20 ; $i++) {
$monthdayyear= date('Y-m-d',mktime(0,0,0,$m,($de-$i),$y));
echo $monthdayyear."<br>";
}

Here i have defined $i=0 and $i<20, so obviously my script will show all the 20 dates before including current date.
The output will be similar to this. Since i ran the script on 2012-10-19 we have our output as,

2012-10-19
2012-10-18
2012-10-17
2012-10-16
2012-10-15
2012-10-14
2012-10-13
2012-10-12
2012-10-11
2012-10-10
2012-10-09
2012-10-08
2012-10-07
2012-10-06
2012-10-05
2012-10-04
2012-10-03
2012-10-02
2012-10-01
2012-09-30

Leave a Reply

Your email address will not be published. Required fields are marked *