almightyegg Posted February 26, 2009 Share Posted February 26, 2009 How would add a certain amount of seconds to a date defined by date()? Eg. current time by server is 2009-02-26 22:05:09 how would I get 2009-02-26 22:05:39?? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 26, 2009 Share Posted February 26, 2009 echo date("Y-m-d H:i:s", strtotime("now +30 seconds")); Quote Link to comment Share on other sites More sharing options...
samshel Posted February 26, 2009 Share Posted February 26, 2009 $dtDate = "2009-02-26 22:05:09"; $tmTime = strtotime($dtDate); $tmNextTime = $tmTime + 30; $dtNextDate = date("Y-m-d H:i:s", $tmNextTime); its the same as the little guy suggested, just instead of current time, u can put any time in the variable. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 26, 2009 Author Share Posted February 26, 2009 Thank you, also how would I get the difference between 2 timestamps? As in which one is bigger... I tried: if($time1>$time2){ }else{ } but no joy Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 26, 2009 Share Posted February 26, 2009 convert them to unix time stamps $time1 = strtotime($row['date1']); $time2 = strtotime($row['date2']); if($time1>$time2){ echo '1 is larger than 2'; }else{ echo '2 is larger than 1'; } Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 26, 2009 Author Share Posted February 26, 2009 You're gonna hate me... I have another problem :s How would I take one timestamp from another? $time1-$time2= X seconds Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 26, 2009 Share Posted February 26, 2009 What you have will return seconds, I believe... take the larger one minus the smaller one. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 26, 2009 Author Share Posted February 26, 2009 Thanks for all your help Quote Link to comment 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.