Posted by: prajapatinilesh | January 7, 2011

PHP Date ( Archived date list )

<?php
$stDtTimeVar = ’12/30/2010 09:00 PM’;
$endDtTimeVar = ’12/30/2010 09:00 AM’;
echo ‘start date:– ‘.$stDtTimeVar;
echo “<br /> <br />”;
echo ‘end date:– ‘.$endDtTimeVar;
echo “<br /> <br />”;

if(strtotime($stDtTimeVar) >= strtotime($endDtTimeVar)) {
echo ‘start date is greater.’;
}
else {
echo ‘end date is greater.’;
}

echo “<br /> <br />”;

$url = $_SERVER[‘PHP_SELF’];
$i=1;
$monthLimit=12;

$currentdate = date(“Y-m”, mktime(0,0,0,date(“m”),1,date(“Y”)));
$currentdate1 = str_replace  ( “-”  , “_”  , $currentdate);

$currentdateDisp=date(“F Y”, mktime(0,0,0,date(“m”),1,date(“Y”)));
echo “<a href=’$url?date=$currentdate1′>”.$currentdateDisp.”</a>”.”<br>”;

while($monthLimit > 0) {

$monthVal = date(“m”)-$i;

$dateDisp = date(“Y-m”, mktime(0,0,0,$monthVal,1,date(“Y”)));
$dateDisp1 = str_replace  ( “-”  , “_”  , $dateDisp);

$dateDisp2 = date(“F Y”, mktime(0,0,0,$monthVal,1,date(“Y”)));
?>
<a href='<?=$url?>?date=<?=$dateDisp1?>’><?=$dateDisp2?></a><br>
<?php
$monthLimit–;
$i=$i+1;
}
?>

Thanks,

Nilesh Prajapati

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: