0

I am writting remider service script it should remind the due amount before 3 days in a particular month once in a year.

My code is working fine for current month, but how to set reminder if current date is 2015-07-30 but the actual due date will be in next month after 3 days. i.e. 2015-08-03. How to count days?

my current code:

<?php
include("configPDO.php");
$timezone = "Asia/Kolkata";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
$curdate = strtotime(date("Y-m-d"));
$unixtime =  strtotime("+3 days",$curdate);
$bday = date("d",$unixtime);
$bmonth = date("m",$unixtime);
$result=$dbh->prepare("SELECT * FROM members WHERE month(date)=$bmonth AND day(date)=$bday");
    $result->execute();

    while($row = $result->fetch(PDO::FETCH_ASSOC)){
      echo $row['member']."</br>";
      echo $row['mobileno']."</br>";
      echo $row['amount'];      
     } 
?>
2
Contributors
1
Reply
11
Views
2 Years
Discussion Span
Last Post by diafol
0

First off, you're using variables inside a prepared statement. The whole point is that the binding takes care of that. Also date is a reserved word so should be backticked. As you're not taking YEAR into account, you could end up with entries for a daydate and month from multiple years.I don't see why you've split this:

$result=$dbh->prepare("SELECT * FROM `members` WHERE month(`date`)=? AND day(`date`)=?");
$result->execute([$bmonth,$bday]);

I would think the better option would be:

$result=$dbh->prepare("SELECT * FROM `members` WHERE `date`=?");
$result->execute([$date]);

Where $date is like this:

$dt = new DateTime();
$date = $dt->add(new DateInterval('P3D'))->format('Y-m-d');
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.