HarryMW Posted April 1, 2011 Share Posted April 1, 2011 Little confuzzled. I have got a bunch of listings that will be printed at the end of the page but I need to subtract a time specified in a textbox (send it to itself) on the page. $row['active'] = (strtotime('$row[etd]') + $rwy1 = $_POST['tmatttextfield']); Well this just converts the time in the database which is always going to be a four character number such as: 1300 for 1PM into a time and adds the textbox value to the time. <td width="50" bgcolor="<?php echo $bc?>"><strong><?php echo date('hi', $row['active']);?></strong></td> That just prints it all out formatting the time to only Hours and Minutes. So just to clarify the user would put in say '10' in the textbox which would constitute 10 minutes. The code above should then define that '10' as 10 minutes. Define the database result, ie. 1500 as 3PM and add the 10 minutes to it so it would become 1510. I have been getting some wierd and wonderful results whilst trying to get it to work. Mainly just 1200 though. Harry. Quote Link to comment https://forums.phpfreaks.com/topic/232415-using-strtotime-to-add-to-a-time/ Share on other sites More sharing options...
HarryMW Posted April 1, 2011 Author Share Posted April 1, 2011 No news? Just to clarify. A typical database entry would be 1500. (3PM) A typical text field entry would 10 or even 00:10:00 (H:M:S) I would like to plus the text field entry onto the database entry. So it would become 1510. Harry. Quote Link to comment https://forums.phpfreaks.com/topic/232415-using-strtotime-to-add-to-a-time/#findComment-1195706 Share on other sites More sharing options...
dcro2 Posted April 1, 2011 Share Posted April 1, 2011 I think if you just do something like this it could work: $timetoadd = "10"; //from your text field $time = "1500"; //from database $newtime = date('Hi', strtotime($time." +".$timetoadd." minutes")); I couldn't get it to work with something like 00:10:00 for some reason, but this is the concept. You can do +10 minutes, hours, months, years, etc. Note: I used 'Hi', not 'hi' because lower-case h is 12-hour time, so you would get 0310. Quote Link to comment https://forums.phpfreaks.com/topic/232415-using-strtotime-to-add-to-a-time/#findComment-1195714 Share on other sites More sharing options...
HarryMW Posted April 2, 2011 Author Share Posted April 2, 2011 Done! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/232415-using-strtotime-to-add-to-a-time/#findComment-1195756 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.