Hi,
Below is the code to add month or year for a date using PHP.
<?php
$date = "2012-01-30";
list($year,$month,$day) = explode("-",$date);
// add month here
$month=$month+1;
// to avoid a month-wrap, set the day to the number of days of the new month if it's too high
$day = min($day,date("t",strtotime($year."-".$month."-01")));
$date = $year."-".$month."-".$day;
$date1_d=date("d",strtotime("$date"));
$date1_D=date("D",strtotime("$date"));
$date1_Y=date("Y",strtotime("$date"));
$date1_F=date("F",strtotime("$date"));
// 2012-02-29
echo $date;
echo "<br>".$date1_d;//29
echo "<br>".$date1_D;//Wed
echo "<br>".$date1_Y;//2012
echo "<br>".$date1_F;//February
?>
Hope it helps.
~ Enjoy
Umar
No comments:
Post a Comment