How to export a datetime value from mysql to php -


i want promotion code feature ecomm website. have variable called $currentdate i'm not sure correct format.

$currentdate = date("y-m-d")  

i compare date in database called expirydate. in database have row promocode = gss2016 (varchar), discount = 0.1 (double, suppose represent 10% discount) , expirydate = 2016-07-28 (datetime in y-m-d if i'm not wrong...) have run query check if promocode exist i'm unsure of how export php , compare current date

$currentdate = date("y-m-d");  session_start();  $conn = mysqli_connect("localhost", "root", "","websitedb");  $promocodeinput = $_post['promocode'];  $sql = "select * promocodedb promocode = '$promocodeinput'";  $codechecker = mysqli_query($conn, $sql) or die (mysqli_error($conn));  if (mysqli_num_rows($codechecker) > 0) {     $fetchdiscount = mysqli_fetch_assoc($codechecker);      $expiry = $fetchdiscount['expirydate'];      if ($expiry > $currentdate)     {         $discountpercentage = $fetchdiscount['discount'];         echo $discountpercentage;          $cookie_value = $discountpercentage;         setcookie("discount", $cookie_value, time() + (60 * 60)); //discount last 1 hour          header("location:cart.php?status=promoapplied");     }     else     {         //header("location:cart.php?status=promoexpired");       } } else {     header("location:cart.php?status=promofail");    } 

y-m-d produces string 2016-jul-25. cannot compare reliablly against string, or mysql date/time formatted-string, 2016-07-25.

string comparison rules never work when comparing numbers/dates:

php > var_dump('2016-jul-25' > '2016-07-25'); bool(true) php > var_dump('2016-jul-25' == '2016-07-25'); bool(false) 

even though 2 versions represent same date, can see comparisons come wrong. string rules, they're not same dates.

as well, note one:

php > var_dump('2016-jul-25' > '2016-mar-25'); bool(false) 

true human parsing standards, because july comes later in year march, false string comparison standards, because j comes earlier in alphabet m, therefore jul version smaller/earlier mar version.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -