ok i just need a little help with this date shiot
i have a form that takes user input for billing periods .. aka start and end
so i end up with 2 vars that look like this
$billstart = $billsinput // a date formated like 2002-05-01
$billend = $billeinput // 2002-05-31
now wut i need to do is to be able to take $billend and add 15 days to it for a dudate giving me a valid date of something like 2002-06-15.
so basically i just want to always have 15 days added to a user inputed $billend and have it automagically adjust whether it needs to bump the month and stuff depending on the given $billend
any help/examples would be greatly appreciated
thanks in advance..
Hud
Simple Date Prob - Help!!
Moderator: General Moderators
OK, this is a pretty easy thing to do in php, weakly typed as it is. just use the following:
Code: Select all
$duedate = strftime("%Y-%m-%d",mktime(0,0,0,substr($billend,5,2),substr($billend,8,2)+15,substr($billend,0,4)));Code: Select all
$duedate = strftime("%Y-%m-%d",mktime(0,0,0,substr($billend,5,2),substr($billend,8,2)+15,substr($billend,0,4)));What about
Code: Select all
$EndAsTimeStamp = StrToTime($billeinput);
//get 15 days as seconds, you could define this as a constant
$NoSeconds = 15*24*60*60;
$DueAsTimeStamp = $EndAsTimeStamp + $NoSeconds;
$DueDate = date('Y-m-d',$DueAsTimeStamp);Code: Select all
$DueDate = date('Y-m-d',StrToTime($billeinput)+(15*24*60*60));Actually, the way I coded it, the function will not generate invalid dates, assuming you aren't using huge numbers. There are many different valid solutions to your problem. I have coded a sample page to demonstrate how these work. Source code is below. http://www.positronicsoftware.com/test.php
If you can understand these examples, you'll see that both methods work equally well.
Code: Select all
$billend="2002-05-03";
echo $billend.':<br>';
$duedate = strftime("%Y-%m-%d",mktime(0,0,0,substr($billend,5,2),substr($billend,8,2)+15,substr($billend,0,4)));
echo $duedate;
$duedate = date('Y-m-d',StrToTime($billend)+(15*24*60*60));
echo '<br>'.$duedate.'<p>';
$billend="2002-05-23";
echo $billend.':<br>';
$duedate = strftime("%Y-%m-%d",mktime(0,0,0,substr($billend,5,2),substr($billend,8,2)+15,substr($billend,0,4)));
echo $duedate;
$duedate = date('Y-m-d',StrToTime($billend)+(15*24*60*60));
echo '<br>'.$duedate.'<p>';