adding days to date for new date with correct month stamp

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
chrismicro
Forum Newbie
Posts: 21
Joined: Fri Nov 12, 2010 7:03 am

adding days to date for new date with correct month stamp

Post by chrismicro »

I currently have this working to post the correct format:


the hour format is 00 -23

the day format is 0-31

month format is from 01-12

code:

$aud1hour = "09";
$aud1day = "20";
$aud1month = "10";

$stamp = mktime($aud1hour,0,0,$aud1month,$aud1day,0);
$formatted_date = date('g:ia, M jS',$stamp);

echo "<font face='geneva, arial, sans serif' size='2' color='#00FF00'>".$formatted_date."</font>";

//THIS WILL PRINT THE CORRECT FORMAT OF

9:00am, Oct 20th


**now here is what I need done, I need to figure out a way that if I add 12 days to $aud1day making it the number 32 What function / code can I use to convert the month to 11 and set the day to 1, or if the month is a 30 day month, or 28 or 29 ( leap year ) instead of using an insane amount of if statements.
chrismicro
Forum Newbie
Posts: 21
Joined: Fri Nov 12, 2010 7:03 am

Re: adding days to date for new date with correct month stam

Post by chrismicro »

this worked:

$aud1hour = "13";
$aud1day = "23";
$aud1month = "12";
$add = "12";

$stamp = mktime($aud1hour,0,0,$aud1month,$aud1day,0);
$formatted_date = date('g:ia, M jS',$stamp);
$end_date = date("g:ia, M jS",strtotime("+".$add." days",$stamp));


echo "date:&nbsp;".$formatted_date."<br><br>";
echo "New Date with&nbsp;".$add." days added:&nbsp;".$end_date;
Post Reply