oz11 Posted November 6, 2022 Share Posted November 6, 2022 (edited) When a form is submitted it updates the users table field ("expired") with $expired = date('Y-m-d H:i:s', strtotime('+ 3 minutes')); Later, if the form is resubmitted it checks the "expired" date/time and compares it to the current date/time. If the information means that the user's expired field is older than the date then the user can reuse the form, else he cannot. Here is a block of code from which i'm having problems... it just keeps on saying "spot on" even when i modify the dates to b before.. $stmt = $pdo->prepare("SELECT expired FROM `users` WHERE user_id = ?"); $stmt->execute([$_SESSION['userID']]); $expire_check = $stmt->fetch(); echo $date = date('Y-m-d H:i:s'); echo "<br>"; echo $expire_check['expired']; if ($expire_check['expired']>= date('Y-m-d H:i:s')){ echo "<br>Too soon!"; } else { echo "spot on"; } Help please. Edit: So how exactly can i get it to display "too soon" or "spot on" from three minutes. I know it has something to do with "strtotime", eg: Quote $expired = date('Y-m-d H:i:s', strtotime('- 3 minutes')); sadly my mental maths is no good. .. this is what I'm trying atm ...: $stmt = $pdo->prepare("SELECT expired FROM `users` WHERE user_id = ?"); $stmt->execute([$_SESSION['userID']]); $expire_check = $stmt->fetch(); echo $date = date('Y-m-d H:i:s'); echo "<br>"; echo $expire_check['expired']; $date1 = date($expire_check['expired'], strtotime('+ 3 minutes')); if ($date1> date('Y-m-d H:i:s')){ echo "<br>Too soon!"; } else { echo "spot on"; } Edit: Basically i need to save the expired date as the current date/time, and in the code add three minutes to this, then compare the +3 minute date to the current date time to decide weather it should be "too soon" or "spot on".. Help plz. Edited November 6, 2022 by oz11 Quote Link to comment https://forums.phpfreaks.com/topic/315498-check-datetime-to-print-expire-or-not/ Share on other sites More sharing options...
oz11 Posted November 6, 2022 Author Share Posted November 6, 2022 Even though I was puzzled before, i think i found a solution.. $stmt = $pdo->prepare("SELECT expired FROM `users` WHERE user_id = ?"); $stmt->execute([$_SESSION['userID']]); $expire_check = $stmt->fetch(); echo $date = date('Y-m-d H:i:s'); echo "<br>"; ///echo $expire_check['expired']; // echo "<br>"; //echo $date1 = date($expire_check['expired'], strtotime('+ 3 minutes')); echo $newDate = date('Y-m-d H:i:s', strtotime($expire_check['expired']. ' +3 minutes')); if ($newDate > $date){ echo "<br>Too soon!"; } else { //echo "<br>spot on"; } thanks. Quote Link to comment https://forums.phpfreaks.com/topic/315498-check-datetime-to-print-expire-or-not/#findComment-1602273 Share on other sites More sharing options...
requinix Posted November 6, 2022 Share Posted November 6, 2022 Unless I'm misunderstanding, right now what you have is, you take the current time and add 3 minutes to know when the form expires, and then later you take that time and add another 3 minutes to it? This: echo $date = date('Y-m-d H:i:s'); echo "<br>"; echo $expire_check['expired']; What was it outputting? Are the two values what you expected them to be? Quote Link to comment https://forums.phpfreaks.com/topic/315498-check-datetime-to-print-expire-or-not/#findComment-1602282 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.