ainoy31 Posted July 3, 2008 Share Posted July 3, 2008 Hello- I am having trouble trying to calculate a billing cycle on a monthly basis. Say the billing cycle start date is 2008-2-15, then the next cycle should start at 2008-03-14. Here is my script that I have tried. echo $Date = '2008-02-15'; $numDays = (date('t', $currentDate = strtotime("$Date"))); echo "A month from now: " . (date('Y-m-d', mktime(0,0,0,date('d', $currentDate)+ $numDays,0,0))); Much appreciation. AM Quote Link to comment Share on other sites More sharing options...
teynon Posted July 3, 2008 Share Posted July 3, 2008 Are you trying to make it exactly 30 days or just one month? I dont see why it should start on the third because that would be giving them a free day? Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 3, 2008 Share Posted July 3, 2008 You can do this: <?php $adate = getdate(); $adate['mon']++; ?> You have to be careful with the 31st and leap years, though. Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted July 3, 2008 Author Share Posted July 3, 2008 I am trying to take into account that there is never 30 days in a bill cycle since the days in the months are different. So, I figure how many days are in the month that the bill cycle starts and then add the total days to get to the next start of the bill cycle. Hope that is not confusing. Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 3, 2008 Share Posted July 3, 2008 Do you mean that you just want to add the total number of days in the relevant month to the respective days? Would that mean that if the cycle starts on January 31st, the next one would be March 3rd (if it isn't a leap year)? Because 31 days after that day is more than the number of days in February. Actually, every 31 day month that is followed by a 30 day month would go to the first of two months later. Did you mean something else, or is that how you want it to work? Quote Link to comment Share on other sites More sharing options...
teynon Posted July 3, 2008 Share Posted July 3, 2008 // Exactly 30 days in the future: date("Y-m-d", mktime(0,0,0,date("m"), date("d")+30, date("Y"))); // Exactly 1 month in the future: date("Y-m-d", mktime(0,0,0,date("m")+1, date("d"), date("Y"))); // Date in future based on how many days are in the current month: date("Y-m-d", mktime(0,0,0,date("m"), date("d")+cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y")), date("Y"))); Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 3, 2008 Share Posted July 3, 2008 Using the strtotime() function is even easier: <?php //Exactly 30 days in the future echo date('Y-m-d',strtotime("+30 days")) . '<br>'; //Exactly 1 month in the future echo date('Y-m-d',strtotime('+1 month')) . '<br>'; // Date in future based on how many days are in the current month: echo date('Y-m-d',strtotime('+' . date('t') . ' days')); ?> Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.