2

My problem is that the 2 dates won't compare or atleast not good.

I tried most of the answers of Comparing two dates. But none of them was a succes.

What I have right know:

else if ($_SESSION['org_id'] != "0" && $_SESSION['part_id'] == 0) {
    require '../conn.php';
    $sql = "SELECT `end_date` FROM `partner_subscriptions` WHERE `user_id` = '" . $dUsrId . "'";
    $result1 = mysqli_query($conn, $sql );
    $row = mysqli_fetch_array($result1);
    if (date('Y-m-d') >= $row['end_date']) {
        header('Location: ../../index');
    } else {
        header('Location: ../../partnersubscription');
    }
} 

One of the things I tried

else if ($_SESSION['org_id'] != "0" && $_SESSION['part_id'] == 0) {
    require '../conn.php';
   // header('Location: ../../partnersubscription');
    $sql = "SELECT `end_date` FROM `partner_subscriptions` WHERE `user_id` = '" . $dUsrId . "'";
    $result1 = mysqli_query($conn, $sql);
    $row = mysqli_fetch_array($result1);
    $today = date("Y-m-d");
    $expire = $row['end_date']; //from database
    $today_time = strtotime($today);
    $expire_time = strtotime($expire);
    if ($expire_time > $today_time) {
        header('Location: ../../index');
    } else {
        header('Location: ../../partnersubscription');
    }
} 

I expect when the date of today is smaller then the date of the row it will go to index otherwise it will go to partnersubscription.

My row end_date looks like this "2019-06-06" and is DATE

xmaster
  • 1,042
  • 7
  • 20

2 Answers2

0

I'd do a query like this:

SELECT * FROM `partner_subscriptions` WHERE `end_date`>=now()  AND `user_id`=$dUsrId;

And then check the number of rows if it's 1 then it hasn't expired if it is 0 then it has expired.

Paddy Hallihan
  • 1,624
  • 3
  • 27
  • 76
0

why not to use mysql to check this condition :

"SELECT  EXISTS( "SELECT 1 FROM `partner_subscriptions` WHERE `user_id` = '" . $dUsrId . "' AND end_date > NOW() "  ) ;

you will get 1 if not expire and 0 if expire p.s. you might need to use >= and not only > ( include or not include today)

Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
Gilad_T
  • 86
  • 6