intellectualmoron Posted May 6, 2008 Share Posted May 6, 2008 hey all, does it exist, various functions avaliable via google but not what im looking for i need to add seconds to a timestamp formatted as "01/01/1990 00:00:00" for example 01/01/1990 00:00:00 + 578530800 seconds = 06/05/2008 00:00:00 ive seen this method used in VB/ASP but not in php... sorry if this is breif... iM Link to comment https://forums.phpfreaks.com/topic/104342-solved-php-dateadd-function-or-similar/ Share on other sites More sharing options...
xenophobia Posted May 6, 2008 Share Posted May 6, 2008 Convert your date to timestamp using strtotime then add up with the value you want. convert back to the format of date you desired using the date function. Link to comment https://forums.phpfreaks.com/topic/104342-solved-php-dateadd-function-or-similar/#findComment-534218 Share on other sites More sharing options...
intellectualmoron Posted May 6, 2008 Author Share Posted May 6, 2008 awesome you put me on the right track there mate. function DateAdd($interval, $number, $date) { $date_time_array = getdate($date); $hours = $date_time_array['hours']; $minutes = $date_time_array['minutes']; $seconds = $date_time_array['seconds']; $month = $date_time_array['mon']; $day = $date_time_array['mday']; $year = $date_time_array['year']; switch ($interval) { case 'y': // add year $year+=$number; break; case 'm': // add month $month+=$number; break; case 'd': // add days $day+=$number; break; case 'w': // add week $day+=($number*7); break; case 'h': // add hour $hours+=$number; break; case 'n': // add minutes $minutes+=$number; break; case 's': // add seconds $seconds+=$number; break; } $timestamp= mktime($hours,$minutes,$seconds,$month,$day,$year); return $timestamp; } $temptime = time(); echo strftime('%Hh%M %A %d %b',$temptime); $temptime = DateAdd('s',578921162,'01/01/1990 00:00:00'); echo '<p>'; #echo strftime('%Hh%M %A %d %b',$temptime); #echo strftime('%d/%m/%Y',$temptime); $temptime = DateAdd('y', 20, $temptime); echo strftime('%Hh%M %A %d %b',$temptime); found this awesome function thats been put together by someone. although i had to use it twice... the initial result was 20 years short of what it needs to be...thus just adding 20 years Link to comment https://forums.phpfreaks.com/topic/104342-solved-php-dateadd-function-or-similar/#findComment-534245 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.