1

I have a website which reminds users to pay their monthly dues via sms.

table: remind

Duedate              | BeforeDue
--------------------------------------------
27 Apr 2017 10:47 AM | 24 Apr 2017 10:47 AM
01 May 2017 10:46 AM | 28 Apr 2017 10:46 AM

I want to select all rows when today's date was between beforedue and duedate

i tried it but something is wrong with my codes

$_POST[today] is formatted date('d M Y h:i A')

$sq = "SELECT * FROM remind WHERE day3 BETWEEN '$_POST[today]' AND due";
$re = $conn->query($sq);

foreach($re as $row) {
    echo ' found: '.$row['day3'];
}
phpwev
  • 29
  • 5
  • There are a few ways to do this depending on how your date value is stored: http://stackoverflow.com/questions/8458290/mysql-select-data-from-database-between-two-dates – M31 Mar 28 '17 at 06:34

1 Answers1

0

update your query like this:

$sq = "SELECT * FROM remind WHERE day3 BETWEEN UNIX_TIMESTAMP(STR_TO_DATE('".$_POST[today]."', '%d %M %Y %h:%i%p')) and UNIX_TIMESTAMP(STR_TO_DATE(Duedate, '%d %M %Y %h:%i%p'))";

Dipanwita Kundu
  • 1,637
  • 1
  • 9
  • 14