Avatar of nisupport
nisupport

asked on 

PHP Recurring dates on the end of the month

I am trying to setup recurring appointments and would like to calculate the end of the month. I have a start date of March 31 and end date of May 31. If I set to increment by a month at a time I will get the following results: March 31, May 1... Instead what I would like to see is January 31 and February 28. It rolls over because there isn't 31 days in April.
PHP

Avatar of undefined
Last Comment
nisupport
Avatar of 60MXG
60MXG

Can you post your code?
ASKER CERTIFIED SOLUTION
Avatar of secondv
secondv
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of nisupport
nisupport

ASKER

I am not sure how to adapt this to my code. Sometimes the code is set to recur on the 15th sometimes it is at the end of the month. I have included a snippet.
if ($period == "Monthly") {
  $interval = '1';
  }
elseif ($period == "Quarterly") {
  $interval = '3';
  }
elseif ($period == "Semi-Annual") {
  $interval = '6';
  }
elseif ($period == "Annual") {
  $interval = '12';
  }				
//$start_datea is set in the form. So it might be 2007-07-31 and end_date is the same and could be for example 2008-07-31
 
$reportdate = $start_datea;		
while ($reportdate <= $end_date) {
  $arrgc = explode("-",  $reportdate);
  $reportdate = date("Y-m-d", mktime(0,0,0, $arrgc[1]+$interval, $arrgc[2], $arrgc[0]));
	}

Open in new window

PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo