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?? Link to comment https://forums.phpfreaks.com/topic/147078-solved-adding-to-date/ 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")); Link to comment https://forums.phpfreaks.com/topic/147078-solved-adding-to-date/#findComment-772128 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. Link to comment https://forums.phpfreaks.com/topic/147078-solved-adding-to-date/#findComment-772131 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 Link to comment https://forums.phpfreaks.com/topic/147078-solved-adding-to-date/#findComment-772134 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'; } Link to comment https://forums.phpfreaks.com/topic/147078-solved-adding-to-date/#findComment-772140 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 Link to comment https://forums.phpfreaks.com/topic/147078-solved-adding-to-date/#findComment-772144 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. Link to comment https://forums.phpfreaks.com/topic/147078-solved-adding-to-date/#findComment-772146 Share on other sites More sharing options...
almightyegg Posted February 26, 2009 Author Share Posted February 26, 2009 Thanks for all your help Link to comment https://forums.phpfreaks.com/topic/147078-solved-adding-to-date/#findComment-772153 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.