arunpatal Posted April 9, 2014 Share Posted April 9, 2014 Hi, I have a variable $last_visited_time contain time. example 15:12:45 i want to add 30min extra to this time variable.... how can i do this??? Quote Link to comment https://forums.phpfreaks.com/topic/287632-add-30min-extra-to-time-variable/ Share on other sites More sharing options...
Solution Barand Posted April 9, 2014 Solution Share Posted April 9, 2014 try $t1 = new DateTime('15:12:45'); $inc = new DateInterval('PT30M'); $t2 = $t1->add($inc); echo $t2->format('H:i:s'); //--> 15:42:45 Quote Link to comment https://forums.phpfreaks.com/topic/287632-add-30min-extra-to-time-variable/#findComment-1475473 Share on other sites More sharing options...
X5HOST Posted April 9, 2014 Share Posted April 9, 2014 Hi Arunpatal, If you're looking to do something like that then I would highly recommend that you take a read of the PHP manual concerning the 'strtotime' function. This function will allow you to convert the time into a TIMESTAMP, to which you can then convert the TIMESTAMP to an extra 30 minutes by simply typing '+ 30 mins'. Below is an example, along with a link to the PHP manual concerning 'strtotime'. $last_visited_time = strtotime('10:00'); $result = date("H:i", strtotime('+30 minutes', $last_visited_time)); You can read the PHP manual relating to this HERE. Good luck, let us know the outcome. Regards, Jason Moore Quote Link to comment https://forums.phpfreaks.com/topic/287632-add-30min-extra-to-time-variable/#findComment-1475552 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.