thefollower Posted September 14, 2008 Share Posted September 14, 2008 I have a problem with my script and am not sure how to get it working correctly. I have it checking to see if 2 hours has passed but it doesn't seem to check it properly. This is what i have: <?php //get date and now date comparison $GetDate = mysql_query("SELECT TIMEDIFF(NOW(), Started) AS MinutesPassed FROM users WHERE UserID='{$_SESSION['Current_User']}'") or die(mysql_error()); $row = mysql_fetch_assoc($GetDate); $Check = strtotime($row['MinutesPassed']); ?> Max Time Length: 02:00:00 <br> Current Time Passed: <?php echo $row['MinutesPassed'];?> <br> <?php // 1221271200 is apparently 02:00:00 in integer format If($row['MinutesPassed'] == '02:00:00' OR $Check > 1221271200){ $UPDATE = mysql_query("UPDATE users SET StartValidate='0' WHERE UserID='{$_SESSION['Current_User']}'") Or die(mysql_error()); ?> You have finished! <br><br> <?php } ?> I get you have finished straight away when i should not be.. it should be waiting 2 hours ... =/ where did i go wrong? Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/ Share on other sites More sharing options...
thefollower Posted September 14, 2008 Author Share Posted September 14, 2008 bumpy. Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-640865 Share on other sites More sharing options...
Garethp Posted September 14, 2008 Share Posted September 14, 2008 You could change the OR to ||. Might help Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-640868 Share on other sites More sharing options...
JasonLewis Posted September 14, 2008 Share Posted September 14, 2008 Make it this: if(time() > 1221271200){ Because you want to check if the current time is past 2. That's my logic of it anyway. Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-640892 Share on other sites More sharing options...
thefollower Posted September 14, 2008 Author Share Posted September 14, 2008 No, im trying to see if the time that has passed from when it started to the current time since is greater than 2 hours.... which is what the query calculates using TIMEDIFF function. But it won't work. Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641102 Share on other sites More sharing options...
thefollower Posted September 14, 2008 Author Share Posted September 14, 2008 bump Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641310 Share on other sites More sharing options...
Mchl Posted September 14, 2008 Share Posted September 14, 2008 Two hours is 7200 seconds, not 120 million... Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641313 Share on other sites More sharing options...
thefollower Posted September 14, 2008 Author Share Posted September 14, 2008 I know lol How ever when i did : $Var = '02:00:00'; $Var = strtotime($Var); Echo $Var; It gives : 1221271200 which is why i'm confused So then i assumed if the number is higher than 1221271200 it would suggest that 2 hours has definitely passed =/. Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641322 Share on other sites More sharing options...
Mchl Posted September 14, 2008 Share Posted September 14, 2008 Do this little experiment <?php echo date("d-m-y h:i:s",strtotime("02:00:00")); ?> Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641331 Share on other sites More sharing options...
thefollower Posted September 14, 2008 Author Share Posted September 14, 2008 This is what i got: 14-09-08 02:00:00 that mean strototime is not the correct function to use? I hate dealing with time in php i just don't understand it =/ Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641342 Share on other sites More sharing options...
Mchl Posted September 14, 2008 Share Posted September 14, 2008 Yup. Whuch means that strtotime("02:00:00") returns a timestamp for 2:00 am TODAY. That's why you got those millions of seconds. If you want to check if two hours passed, just check for 7200 seconds passed. No need for strtotime for that. Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641344 Share on other sites More sharing options...
thefollower Posted September 14, 2008 Author Share Posted September 14, 2008 How is that possible though ? Time isn't going to be in a pure integer format to make the comparison or is php flexible enough to do it like so: If($row['MinutesPassed'] > 7200) Based on my query that is ? Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641351 Share on other sites More sharing options...
Mchl Posted September 14, 2008 Share Posted September 14, 2008 In what format do you store time in Started column? Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641354 Share on other sites More sharing options...
thefollower Posted September 14, 2008 Author Share Posted September 14, 2008 Y-m-d : h-m-s Is the format i use. Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641358 Share on other sites More sharing options...
Mchl Posted September 14, 2008 Share Posted September 14, 2008 but do you store it as a string, or as a DATETIME or TIMESTAMP Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641360 Share on other sites More sharing options...
thefollower Posted September 14, 2008 Author Share Posted September 14, 2008 Oh sorry i store it as a TimeStamp Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641365 Share on other sites More sharing options...
Mchl Posted September 14, 2008 Share Posted September 14, 2008 Great. So let's modify your query a little. $query = "SELECT TIME_TO_SEC(TIMEDIFF(NOW(), Started)) AS SecondsPassed FROM users WHERE UserID='{$_SESSION['Current_User']}'"; Now you should get number of secods that passed from the date stored in 'Started' Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641372 Share on other sites More sharing options...
thefollower Posted September 14, 2008 Author Share Posted September 14, 2008 Awesome! Theres a function for everything, i wish i just know what function i needed when ever i get these problems would save me a world of trouble i always find the wrong functions Thanks for the help Mchl ! Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641384 Share on other sites More sharing options...
Mchl Posted September 14, 2008 Share Posted September 14, 2008 My hobby: Browse the manual when everyone else is watching SuperBowl ok... that was a joke. There's no SuperBowl here. Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641393 Share on other sites More sharing options...
thefollower Posted September 14, 2008 Author Share Posted September 14, 2008 Well i do the same on php website but i only found strtotime as something potentially useful. Didn't find the function you found for mysql so presumed it was not a real function ! Well any way thanks for the help again Link to comment https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/#findComment-641399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.