Hi Guys,
I am working on a database for managing my projects, I would like to have a fucntion that can alert when quaterly and anual Reports are due basing on Project start dates.

Please I need ideas if possible a working code too, still learning PHP.

Any help much appreciated.

Recommended Answers

All 4 Replies

Member Avatar for LastMitch

I am working on a database for managing my projects, I would like to have a fucntion that can alert when quaterly and anual Reports are due basing on Project start dates.

Do you have at least a table or database?

What code you have done so far?

I mean regardless whether you still learning PHP you still need to learn the basic of a query.

function getNextBillDate($start_date) {

  $date_array = explode("-",$start_date); // split the array

  $year = $date_array[0];
  $month = $date_array[1];
  $day = $date_array[2];

  if (date("d") <= $day) {
    $billMonth = (int)date("m");
  }else{
    $billMonth = date("m")+1;
  }
  $billMonthDays = cal_days_in_month(CAL_GREGORIAN, ($billMonth), date("Y"));

  if ($billMonthDays > $day) {
    $billDay = $day;
  }else{
    $billDay = $billMonthDays;
  }

  $nextBillDate = $billMonth . "/" . $billDay . "/" . date("Y");

  return $nextBillDate;
}
//Yes I have the database done the projects have start dates....so my function should get the
//start date and add 3 months, 6 months and 12 months to generate the dates for the Quarterly
//bi-annual and annual dates. tried using this code but not getting the actuall days 
//this code gets 1 month from a given date but if the given date is greater than todays date,
//the month does not change ....I need to modify it to suit my need and also how to handle //Dec.....thanks 
Member Avatar for diafol

What do you mean by alert? As in email? Message to screen?
Your code seems a bit verbose. You could do it like this:

$date = '2013-05-19';
$inputFormat = 'Y-m-d';
$outputFormat = 'd/m/Y';
$interval = 'P1M'; //1 month

$date = DateTime::createFromFormat($inputFormat, $date);
$date->add(new DateInterval($interval));
echo $date->format($outputFormat);

OR, you could even do it in a query:

SELECT ..., mydatefield + INTERVAL 1 MONTH AS nextbill FROM ...

Thanks Diafol, I did it in a query, problem is if start date is say "2013-02-01" and we are now in "2013-07-01" I would want to display "2013-08-01" as the next quarter date not a fixed "213-05-01"

select date_add(startdate, interval 1 Quarter)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.