jmurch Posted June 19, 2011 Share Posted June 19, 2011 I am trying to work around something and need to add and subtract one second to the times. I'm using the format: $now = date("Y-m-d H:i:s"); I need to ultimatley have the results such as: $now = (date("Y-m-d H:i:s") - :01); or $now = (date("Y-m-d H:i:s") + :01); TIA, Jeff Quote Link to comment https://forums.phpfreaks.com/topic/239754-addsubtract-one-second-from-datey-m-d-his/ Share on other sites More sharing options...
xyph Posted June 19, 2011 Share Posted June 19, 2011 Use timestamps instead $stamp = time(); echo 'One second ago '. date("Y-m-d H:i:s", $stamp-1); Quote Link to comment https://forums.phpfreaks.com/topic/239754-addsubtract-one-second-from-datey-m-d-his/#findComment-1231622 Share on other sites More sharing options...
mikesta707 Posted June 19, 2011 Share Posted June 19, 2011 You can add a unix timestamp into the second parameter of the date() function in order to use your own time stamp and have it formatted via date.. In this case, your own time stamp would be the current time minus 1 second. You can get the current time stamp using the time() function. So if we do $time = time() -1;//time stamp is in seconds, so now -1 would be the current date minus 1 $now = date("Y-m-d H:i:s", $time); Hope this helps Edit: Ninjad by xyph, but I believe xyph mean to use time() instead of timestamp() (correct me if I'm wrong) So im posting anyways Quote Link to comment https://forums.phpfreaks.com/topic/239754-addsubtract-one-second-from-datey-m-d-his/#findComment-1231623 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.