mahenda Posted August 9, 2020 Share Posted August 9, 2020 how to calculate the difference between the current datetime from the stored one(ie date_field = 2020-08-09 23:13:06) in order to compare with 15min, i mean if the resulted time exceed 15 min and not the same day(date) the provided link will show expire message. i.e $some_variable = $date_in_db - current_date; if((time() - $some_variable > 15*60) && not the same day or the same day){ echo 'the link has expired'; } Quote Link to comment https://forums.phpfreaks.com/topic/311301-datetime-calculation-in-php/ Share on other sites More sharing options...
gw1500se Posted August 9, 2020 Share Posted August 9, 2020 You need to use strtotime. It will create a time stamp then you compare the time stamps directly. if(strtotime("+15 minutes") < strtotime($some_variable)) { Quote Link to comment https://forums.phpfreaks.com/topic/311301-datetime-calculation-in-php/#findComment-1580498 Share on other sites More sharing options...
mahenda Posted August 10, 2020 Author Share Posted August 10, 2020 8 hours ago, gw1500se said: You need to use strtotime. It will create a time stamp then you compare the time stamps directly. if(strtotime("+15 minutes") < strtotime($some_variable)) { 8 hours ago, gw1500se said: You need to use strtotime. It will create a time stamp then you compare the time stamps directly. if(strtotime("+15 minutes") < strtotime($some_variable)) { what if user click the link by tomorrow at the same time Quote Link to comment https://forums.phpfreaks.com/topic/311301-datetime-calculation-in-php/#findComment-1580509 Share on other sites More sharing options...
gw1500se Posted August 10, 2020 Share Posted August 10, 2020 It doesn't matter. Strtotime includes the date. Quote Link to comment https://forums.phpfreaks.com/topic/311301-datetime-calculation-in-php/#findComment-1580527 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.