the problem i am having is that it will work great for the current year, and up updating dec to jan 2004, anything after that reverts it back to 2003
so
Jan 31, 2003 -> Feb 28, 2003
Oct 4, 2003 -> Nove 4, 2003
Dec 31, 2003 -> Jan 31, 2004
Jan 31, 2004 -> Feb 28, 2003(actually it shows up as march 3rd i think?)
here is my code.
Code: Select all
<?php
//TESTING VARIABLES
//nov 04, 2003 12:30:15
$date_DATE = "20031104123015";
//Extract the date from the mysql format
$date_year = substr($date_DATE, 0, 4);
$date_month = substr($date_DATE, 4, 2);
$date_day = substr($date_DATE, 6, 2);
$date_hour = substr($date_DATE, 8, 2);
$date_min = substr($date_DATE, 10, 2);
$date_second = substr($date_DATE, 12, 2);
//code to check the date and change it accordingly
//if date total days in the month is less than the current date, like going from jan to feb use the total days in the next month
$NMonth = date("t", mktime(1,1,1,($date_month)+1,1,$date_year));
//Days in next month.
$CMonthDays = date("d", mktime(1,1,1,$date_month,$date_day,0,$date_year));
if ($NMonth < $CMonthDays)
{
$CMonthDays = $NMonth;
}
$OldDate = mktime($date_hour, $date_min, $date_second, $date_month, $date_day, $date_year);
$Updatemydate = mktime($date_hour, $date_min, $date_second, ($date_month)+1, $CMonthDays);
echo "Start: ".date("Y/m/d H:i:s",$OldDate)."<br>";
echo "End: ".date("Y/m/d H:i:s",$Updatemydate)."<br><br>";
?>thanks.