nadeemshafi9 Posted April 2, 2009 Share Posted April 2, 2009 hello guys i have a time 00:00:00 and a datetime 0000-00-00 11:11:00 i would like to add the time to the datetime and preserve the date prior to the add in the resultant datetime. Thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/152224-add-time-to-datetime/ Share on other sites More sharing options...
Yesideez Posted April 2, 2009 Share Posted April 2, 2009 int mktime ([ int $hour= date("H") [, int $minute= date("i") [, int $second= date("s") [, int $month= date("n") [, int $day= date("j") [, int $year= date("Y") [, int $is_dst= -1 ]]]]]]] ) $thetme='00:00:10'; $justTime=mktime(substr($thetime,0,2),substr($thetime,3,2),substr($thetime,6,2),0,0,0); $dateTime=strtotime('0000-00-00 11:11:00'); $addedtogether=$dateTime+$justTime; echo date('d-M-Y H:i:s',$addedtogether); See how that works. Quote Link to comment https://forums.phpfreaks.com/topic/152224-add-time-to-datetime/#findComment-799375 Share on other sites More sharing options...
nadeemshafi9 Posted April 2, 2009 Author Share Posted April 2, 2009 int mktime ([ int $hour= date("H") [, int $minute= date("i") [, int $second= date("s") [, int $month= date("n") [, int $day= date("j") [, int $year= date("Y") [, int $is_dst= -1 ]]]]]]] ) $thetme='00:00:10'; $justTime=mktime(substr($thetime,0,2),substr($thetime,3,2),substr($thetime,6,2),0,0,0); $dateTime=strtotime('0000-00-00 11:11:00'); $addedtogether=$dateTime+$justTime; echo date('d-M-Y H:i:s',$addedtogether); See how that works. thnaks man il try it out tommorow Quote Link to comment https://forums.phpfreaks.com/topic/152224-add-time-to-datetime/#findComment-799756 Share on other sites More sharing options...
MadTechie Posted April 2, 2009 Share Posted April 2, 2009 why now just $thetime='00:00:10'; $dateTime='0000-00-00 11:11:00'; echo date('d-M-Y H:i:s',(strtotime($dateTime) + strtotime($thetime) ) ); Quote Link to comment https://forums.phpfreaks.com/topic/152224-add-time-to-datetime/#findComment-799761 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.