rwahdan1978 Posted April 23 Share Posted April 23 I am trying to get the current time and add 10 minutes before saving to DB. $addingTenMinutes= strtotime('now() + 10 minute'); $end_time = date('Y-m-d H:i:s', $addingFiveMinutes); why it is not working? Quote Link to comment https://forums.phpfreaks.com/topic/327484-how-to-get-the-current-time-and-add-10-minutes/ Share on other sites More sharing options...
Solution Olumide Posted April 23 Solution Share Posted April 23 7 minutes ago, rwahdan1978 said: I am trying to get the current time and add 10 minutes before saving to DB. $addingTenMinutes= strtotime('now() + 10 minute'); $end_time = date('Y-m-d H:i:s', $addingFiveMinutes); why it is not working? You're assigning $addingTenMinutes but then using $addingFiveMinutes, which doesn't exist. Also, strtotime('now() + 10 minute') is not a valid syntax for strtotime. Here is a corrected version: $addingTenMinutes = strtotime('+10 minutes'); $end_time = date('Y-m-d H:i:s', $addingTenMinutes); 1 Quote Link to comment https://forums.phpfreaks.com/topic/327484-how-to-get-the-current-time-and-add-10-minutes/#findComment-1653320 Share on other sites More sharing options...
Barand Posted April 23 Share Posted April 23 If the only reason for that value is to write to the DB then you can do it in the insert query... INSERT INTO tablename (colx, coly, colz) VALUES (?, ?, NOW() + INTERVAL 10 MINUTE) 1 Quote Link to comment https://forums.phpfreaks.com/topic/327484-how-to-get-the-current-time-and-add-10-minutes/#findComment-1653321 Share on other sites More sharing options...
gizmola Posted Sunday at 08:15 PM Share Posted Sunday at 08:15 PM strtotime() returns a unix timestamp value. Timestamps are an integer value which is the number of seconds since the January 1, 1970 00:00:00 UTC. Helpers like "+10 minute" are nice for abstraction, but all the minute addition does is add (minutes * 60) to the value. So you might note that this code will print "Same". $t1 = strtotime("now") + 10 * 60; $t2 = strtotime("+10 Minute"); if ($t1 == $t2) { echo "Same\n"; } An important limitation of strtotime is that it doesn't have any concept of timezone, so in most cases you should use PHP DateTime classes, which do allow you to account for timezones and translate between them. You also need to be aware of what the configured locale settings of your server are. In most cases servers should be setup to be UTC, and thus datetime values set in the database will also be UTC. This is the best practice. When you develop your application you want to be aware of the server and PHP settings, and translate the date/time values at presentation time, by applying the desired timezone relevant to your server or the client. Quote Link to comment https://forums.phpfreaks.com/topic/327484-how-to-get-the-current-time-and-add-10-minutes/#findComment-1653466 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.