GreenSmurf Posted February 18, 2010 Share Posted February 18, 2010 What I need the code to check is that $reQuest is 24 hours in the past then return a time based on how long ago that was in the past if 24 hours has not passed. if ($reQuest!=""){ if (is_on_interval($phpdate,$getdate,24)==false){ //24 hours has not passed. $timePass=false; //echo $reQuest."<br />"; //debug lines of code //echo phpversion(); // Installed 5.3.1 but still registered as 5.2.2 --odd $start = new DateTime($reQuest); //First or start date to be check as pulled from the database. $time = $start->diff(new DateTime(date("Y-m-d H:i:s", $phptime))); //Check the difference in date with diff() available in 5.3.1 }else{$timePass=true;} } The problem is that 5.3.1 did not install properly and being such I am trying to figure out a new way to get the difference in time from the DateTime in the database and the current time obtained by PHP. The $reQuest variable has a value of 2010-02-18 12:47:15 Any help would be appreciated. Thank you. -GS Quote Link to comment https://forums.phpfreaks.com/topic/192558-check-datetime-in-php/ Share on other sites More sharing options...
schilly Posted February 18, 2010 Share Posted February 18, 2010 if you do UNIX_TIMESTAMP(db_date_column) in your query you can turn the date value into a unix timestamp. then check that against time() - 60*60*24 (24 hrs ago) Quote Link to comment https://forums.phpfreaks.com/topic/192558-check-datetime-in-php/#findComment-1014516 Share on other sites More sharing options...
GreenSmurf Posted February 18, 2010 Author Share Posted February 18, 2010 if you do UNIX_TIMESTAMP(db_date_column) in your query you can turn the date value into a unix timestamp. then check that against time() - 60*60*24 (24 hrs ago) I was trying to avoid the UNIX_TIMESTAMP because of the date limitations placed upon it. Plus, I am not trying to limit the query anyway because I am accessing other information in the table from the database. I need to compare the m in PHP. Quote Link to comment https://forums.phpfreaks.com/topic/192558-check-datetime-in-php/#findComment-1014545 Share on other sites More sharing options...
schilly Posted February 18, 2010 Share Posted February 18, 2010 Sorry. What are the limitations? Nothing previous to 1970? You can get the UNIX_TIMESTAMP in addition to the standard MYSQL TIMESTAMP in your query. Quote Link to comment https://forums.phpfreaks.com/topic/192558-check-datetime-in-php/#findComment-1014547 Share on other sites More sharing options...
greatstar00 Posted February 18, 2010 Share Posted February 18, 2010 not only before 1970 but after 2038 Quote Link to comment https://forums.phpfreaks.com/topic/192558-check-datetime-in-php/#findComment-1014551 Share on other sites More sharing options...
GreenSmurf Posted February 18, 2010 Author Share Posted February 18, 2010 not only before 1970 but after 2038 Thank you. You beat me to it. The issue is more that I just want to compare the dates. I thought I was on to something with this little bit of code but I have again hit a wall. $mysqldate = date($reQuest, $phpdate); $phpdate = strtotime($mysqldate); Any more ideas or code snippets would be appreciated. -GS Quote Link to comment https://forums.phpfreaks.com/topic/192558-check-datetime-in-php/#findComment-1014554 Share on other sites More sharing options...
schilly Posted February 18, 2010 Share Posted February 18, 2010 I see the limitations but your still converting the mysql date to a unix timestamp in that code. whats the difference if you do it in mysql or php? Quote Link to comment https://forums.phpfreaks.com/topic/192558-check-datetime-in-php/#findComment-1014561 Share on other sites More sharing options...
GreenSmurf Posted February 18, 2010 Author Share Posted February 18, 2010 I see the limitations but your still converting the mysql date to a unix timestamp in that code. whats the difference if you do it in mysql or php? Got it. Its messy but the functionality is there: if ($reQuest!=""){ $timeSub = date("h:i A", strtotime('+1 day +1 minute '.$reQuest)); $timeNow = date("Y-m-d H:i:s", time()); $timeNow = strtotime($timeNow); //echo $timeNow."<br />"; //echo $reQuest."<br />"; $timeComp = date("Y-m-d H:i:s", strtotime('+1 day '.$reQuest)); $timeComp = strtotime($timeComp); //echo $timeComp."<br />"; if ($timeNow <= $timeComp){ $timePass=false; }else{$timePass=true;} Hope this helps anyone else who might need this sort of calc. -GS Quote Link to comment https://forums.phpfreaks.com/topic/192558-check-datetime-in-php/#findComment-1014569 Share on other sites More sharing options...
schilly Posted February 19, 2010 Share Posted February 19, 2010 wow. you can definitely shorten that down. you're still limited by unix timestamp constraints using that code so I don't see why you don't just do it in mysql. use UNIX_TIMESTAMP to convert the value from the db in your query. if you need the mysql datestamp for something else just pull both values. if($db_unix_time < (time() - 86400)) return true; else return false; Quote Link to comment https://forums.phpfreaks.com/topic/192558-check-datetime-in-php/#findComment-1014573 Share on other sites More sharing options...
GreenSmurf Posted February 19, 2010 Author Share Posted February 19, 2010 wow. you can definitely shorten that down. you're still limited by unix timestamp constraints using that code so I don't see why you don't just do it in mysql. use UNIX_TIMESTAMP to convert the value from the db in your query. if you need the mysql datestamp for something else just pull both values. if($db_unix_time < (time() - 86400)) return true; else return false; You are right about PHP doing the calculation in UNIX_TIMESTAMP but at least it is not in the DB for now and I just need to find a better solution to avoid the UNIX_TIMESTAMP. Quote Link to comment https://forums.phpfreaks.com/topic/192558-check-datetime-in-php/#findComment-1014908 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.