robcrozier Posted December 12, 2007 Share Posted December 12, 2007 Hi all, what im trying to do is add or take away one minute from a time which comes from a databes. what im currently doing is calling a 'datetime' field from the database and then using the explode() function to seperate the date and the time. once i am left with the time, how can i get PHP to treat it like a time and either add or remove one minute? I think i'm over complicating things at the minute! Any help would be great! Cheers! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 12, 2007 Share Posted December 12, 2007 A datetime file will be returned to your PHP script in the form of "yyyy-dd-mm hh:mm:ss", process that string with the strtotime() function. Then you can add or substract 60 from that value. Ken Quote Link to comment Share on other sites More sharing options...
robcrozier Posted December 12, 2007 Author Share Posted December 12, 2007 OK, thanks for the reply Ken but im a bit of a novice when it comes to time functions in PHP. How would i process it with PHP strtotime() function. Also, i might mention that i would also like to convert some user input in the form of HH:MM:SS to a valid php time var so that i can compare etc.. cheers! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 12, 2007 Share Posted December 12, 2007 Read the manual pages on strtotime() and date(). They are really quite helpful. They also have alot of good examples to use. Ken Quote Link to comment Share on other sites More sharing options...
robcrozier Posted December 12, 2007 Author Share Posted December 12, 2007 i just can't understand how to get PHP to treat a string (in the form of a time: HH:MM:SS) as a time var? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 12, 2007 Share Posted December 12, 2007 You can use the strtotime() function to convert the string to an integer containing the number of seconds since 1970-1-1. <?php $str = '16:10:24'; $tim = strtotime($str); echo $tim ."<br>"; $tim += 60; echo date('G:i:s',$tim) . "\n"; ?> Ken Quote Link to comment Share on other sites More sharing options...
lemmin Posted December 12, 2007 Share Posted December 12, 2007 You can do this with mysql. Something like SELECT SUBTIME(thedatetime, '01:00:00') as subbedtime FROM table... Here is the documentation: http://dev.mysql.com/tech-resources/articles/4.1/time.html Quote Link to comment Share on other sites More sharing options...
robcrozier Posted December 12, 2007 Author Share Posted December 12, 2007 thanks Ken that's just what i was after! Quote Link to comment 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.